Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110737303
D43464.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
13 KB
Referenced Files
None
Subscribers
None
D43464.diff
View Options
diff --git a/tests/sys/fs/fusefs/bmap.cc b/tests/sys/fs/fusefs/bmap.cc
--- a/tests/sys/fs/fusefs/bmap.cc
+++ b/tests/sys/fs/fusefs/bmap.cc
@@ -188,7 +188,7 @@
const off_t filesize = 2 * m_maxbcachebuf;
const ino_t ino = 42;
mode_t mode = S_IFREG | 0644;
- void *buf;
+ char *buf;
int fd;
int ngetattrs;
@@ -243,11 +243,12 @@
out.body.attr.attr.size = filesize / 2;
})));
- buf = calloc(1, filesize);
+ buf = new char[filesize]();
fd = open(FULLPATH, O_RDWR);
ASSERT_LE(0, fd) << strerror(errno);
read(fd, buf, filesize);
+ delete[] buf;
leak(fd);
}
diff --git a/tests/sys/fs/fusefs/copy_file_range.cc b/tests/sys/fs/fusefs/copy_file_range.cc
--- a/tests/sys/fs/fusefs/copy_file_range.cc
+++ b/tests/sys/fs/fusefs/copy_file_range.cc
@@ -197,7 +197,7 @@
const char RELPATH1[] = "src.txt";
const char FULLPATH2[] = "mountpoint/dst.txt";
const char RELPATH2[] = "dst.txt";
- void *buf0, *buf1, *buf;
+ char *buf0, *buf1, *buf;
const uint64_t ino1 = 42;
const uint64_t ino2 = 43;
const uint64_t fh1 = 0xdeadbeef1a7ebabe;
@@ -209,7 +209,7 @@
ssize_t len = m_maxbcachebuf;
int fd1, fd2;
- buf0 = malloc(m_maxbcachebuf);
+ buf0 = new char[m_maxbcachebuf];
memset(buf0, 42, m_maxbcachebuf);
expect_lookup(RELPATH1, ino1, S_IFREG | 0644, fsize1, 1);
@@ -240,7 +240,7 @@
fd2 = open(FULLPATH2, O_RDWR);
// Prime cache
- buf = malloc(m_maxbcachebuf);
+ buf = new char[m_maxbcachebuf];
ASSERT_EQ(m_maxbcachebuf, pread(fd2, buf, m_maxbcachebuf, start2))
<< strerror(errno);
EXPECT_EQ(0, memcmp(buf0, buf, m_maxbcachebuf));
@@ -249,7 +249,7 @@
ASSERT_EQ(len, copy_file_range(fd1, &start1, fd2, &start2, len, 0));
// Read again. This should bypass the cache and read direct from server
- buf1 = malloc(m_maxbcachebuf);
+ buf1 = new char[m_maxbcachebuf];
memset(buf1, 69, m_maxbcachebuf);
start2 -= len;
expect_read(ino2, start2, m_maxbcachebuf, m_maxbcachebuf, buf1, -1,
@@ -258,9 +258,9 @@
<< strerror(errno);
EXPECT_EQ(0, memcmp(buf1, buf, m_maxbcachebuf));
- free(buf1);
- free(buf0);
- free(buf);
+ delete[] buf1;
+ delete[] buf0;
+ delete[] buf;
leak(fd1);
leak(fd2);
}
@@ -343,8 +343,8 @@
int fd;
const mode_t mode = 0644;
- fbuf = (uint8_t*)calloc(1, fsize);
- wbuf = (uint8_t*)malloc(wsize);
+ fbuf = new uint8_t[fsize]();
+ wbuf = new uint8_t[wsize];
memset(wbuf, 1, wsize);
expect_lookup(RELPATH, ino, S_IFREG | mode, fsize, 1);
@@ -383,8 +383,8 @@
r = copy_file_range(fd, &offset2_in, fd, &offset2_out, copysize, 0);
ASSERT_EQ(copysize, (size_t)r) << strerror(errno);
- free(wbuf);
- free(fbuf);
+ delete[] wbuf;
+ delete[] fbuf;
}
diff --git a/tests/sys/fs/fusefs/fallocate.cc b/tests/sys/fs/fusefs/fallocate.cc
--- a/tests/sys/fs/fusefs/fallocate.cc
+++ b/tests/sys/fs/fusefs/fallocate.cc
@@ -415,14 +415,14 @@
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
struct spacectl_range rqsr, rmsr;
- void *buf;
+ char *buf;
uint64_t ino = 42;
uint64_t fsize = 2000;
uint64_t offset = 500;
uint64_t length = 1000;
int fd;
- buf = malloc(length);
+ buf = new char[length];
expect_lookup(RELPATH, ino, S_IFREG | 0644, fsize, 1);
expect_open(ino, 0, 1);
@@ -437,7 +437,7 @@
EXPECT_EQ((off_t)(offset + length), rmsr.r_offset);
leak(fd);
- free(buf);
+ delete[] buf;
}
/*
diff --git a/tests/sys/fs/fusefs/io.cc b/tests/sys/fs/fusefs/io.cc
--- a/tests/sys/fs/fusefs/io.cc
+++ b/tests/sys/fs/fusefs/io.cc
@@ -283,7 +283,8 @@
void do_mapread(off_t offs, ssize_t size)
{
- void *control_buf, *p;
+ char *control_buf;
+ void *p;
off_t pg_offset, page_mask;
size_t map_size;
@@ -295,8 +296,7 @@
offs - pg_offset);
ASSERT_NE(p, MAP_FAILED) << strerror(errno);
- control_buf = malloc(size);
- ASSERT_NE(nullptr, control_buf) << strerror(errno);
+ control_buf = new char[size];
ASSERT_EQ(size, pread(m_control_fd, control_buf, size, offs))
<< strerror(errno);
@@ -304,18 +304,16 @@
compare((void*)((char*)p + pg_offset), control_buf, offs, size);
ASSERT_EQ(0, munmap(p, map_size)) << strerror(errno);
- free(control_buf);
+ delete[] control_buf;
}
void do_read(off_t offs, ssize_t size)
{
- void *test_buf, *control_buf;
+ char *test_buf, *control_buf;
ssize_t r;
- test_buf = malloc(size);
- ASSERT_NE(nullptr, test_buf) << strerror(errno);
- control_buf = malloc(size);
- ASSERT_NE(nullptr, control_buf) << strerror(errno);
+ test_buf = new char[size];
+ control_buf = new char[size];
errno = 0;
r = pread(m_test_fd, test_buf, size, offs);
@@ -327,8 +325,8 @@
compare(test_buf, control_buf, offs, size);
- free(control_buf);
- free(test_buf);
+ delete[] control_buf;
+ delete[] test_buf;
}
void do_mapwrite(off_t offs, ssize_t size)
@@ -343,8 +341,7 @@
pg_offset = offs & page_mask;
map_size = pg_offset + size;
- buf = (char*)malloc(size);
- ASSERT_NE(nullptr, buf) << strerror(errno);
+ buf = new char[size];
for (i=0; i < size; i++)
buf[i] = random();
@@ -364,7 +361,7 @@
ASSERT_EQ(size, pwrite(m_control_fd, buf, size, offs))
<< strerror(errno);
- free(buf);
+ delete[] buf;
ASSERT_EQ(0, munmap(p, map_size)) << strerror(errno);
}
@@ -373,8 +370,7 @@
char *buf;
long i;
- buf = (char*)malloc(size);
- ASSERT_NE(nullptr, buf) << strerror(errno);
+ buf = new char[size];
for (i=0; i < size; i++)
buf[i] = random();
@@ -384,7 +380,7 @@
<< strerror(errno);
m_filesize = std::max(m_filesize, offs + size);
- free(buf);
+ delete[] buf;
}
};
diff --git a/tests/sys/fs/fusefs/read.cc b/tests/sys/fs/fusefs/read.cc
--- a/tests/sys/fs/fusefs/read.cc
+++ b/tests/sys/fs/fusefs/read.cc
@@ -1216,8 +1216,7 @@
char buf[bufsize];
const char *contents1 = CONTENTS0 + bufsize;
- contents = (char*)calloc(1, filesize);
- ASSERT_NE(nullptr, contents);
+ contents = new char[filesize]();
memmove(contents, CONTENTS0, strlen(CONTENTS0));
expect_lookup(RELPATH, ino, filesize);
@@ -1235,7 +1234,7 @@
ASSERT_EQ(bufsize, read(fd, buf, bufsize)) << strerror(errno);
ASSERT_EQ(0, memcmp(buf, contents1, bufsize));
leak(fd);
- free(contents);
+ delete[] contents;
}
/* Reading with sendfile should work (though it obviously won't be 0-copy) */
@@ -1332,10 +1331,9 @@
char *rbuf, *contents;
off_t offs;
- contents = (char*)malloc(filesize);
- ASSERT_NE(nullptr, contents);
+ contents = new char[filesize];
memset(contents, 'X', filesize);
- rbuf = (char*)calloc(1, bufsize);
+ rbuf = new char[bufsize]();
expect_lookup(RELPATH, ino, filesize);
expect_open(ino, 0, 1);
@@ -1357,8 +1355,8 @@
ASSERT_EQ(0, memcmp(rbuf, contents, bufsize));
leak(fd);
- free(rbuf);
- free(contents);
+ delete[] rbuf;
+ delete[] contents;
}
INSTANTIATE_TEST_SUITE_P(RA, ReadAhead,
diff --git a/tests/sys/fs/fusefs/setattr.cc b/tests/sys/fs/fusefs/setattr.cc
--- a/tests/sys/fs/fusefs/setattr.cc
+++ b/tests/sys/fs/fusefs/setattr.cc
@@ -448,7 +448,7 @@
TEST_F(Setattr, truncate_discards_cached_data) {
const char FULLPATH[] = "mountpoint/some_file.txt";
const char RELPATH[] = "some_file.txt";
- void *w0buf, *r0buf, *r1buf, *expected;
+ char *w0buf, *r0buf, *r1buf, *expected;
off_t w0_offset = 0;
size_t w0_size = 0x30000;
off_t r0_offset = 0;
@@ -463,18 +463,13 @@
int fd, r;
bool should_have_data = false;
- w0buf = malloc(w0_size);
- ASSERT_NE(nullptr, w0buf) << strerror(errno);
+ w0buf = new char[w0_size];
memset(w0buf, 'X', w0_size);
- r0buf = malloc(r0_size);
- ASSERT_NE(nullptr, r0buf) << strerror(errno);
- r1buf = malloc(r1_size);
- ASSERT_NE(nullptr, r1buf) << strerror(errno);
+ r0buf = new char[r0_size];
+ r1buf = new char[r1_size];
- expected = malloc(r1_size);
- ASSERT_NE(nullptr, expected) << strerror(errno);
- memset(expected, 0, r1_size);
+ expected = new char[r1_size]();
expect_lookup(RELPATH, ino, mode, 0, 1);
expect_open(ino, O_RDWR, 1);
@@ -558,10 +553,10 @@
r = memcmp(expected, r1buf, r1_size);
ASSERT_EQ(0, r);
- free(expected);
- free(r1buf);
- free(r0buf);
- free(w0buf);
+ delete[] expected;
+ delete[] r1buf;
+ delete[] r0buf;
+ delete[] w0buf;
leak(fd);
}
diff --git a/tests/sys/fs/fusefs/write.cc b/tests/sys/fs/fusefs/write.cc
--- a/tests/sys/fs/fusefs/write.cc
+++ b/tests/sys/fs/fusefs/write.cc
@@ -311,10 +311,8 @@
uint64_t oldsize = m_maxbcachebuf / 2;
int fd;
- oldcontents = (char*)calloc(1, oldsize);
- ASSERT_NE(nullptr, oldcontents) << strerror(errno);
- oldbuf = (char*)malloc(oldsize);
- ASSERT_NE(nullptr, oldbuf) << strerror(errno);
+ oldcontents = new char[oldsize]();
+ oldbuf = new char[oldsize];
expect_lookup(RELPATH, ino, oldsize);
expect_open(ino, 0, 1);
@@ -332,8 +330,8 @@
/* Write the new data. There should be no more read operations */
ASSERT_EQ(BUFSIZE, write(fd, CONTENTS, BUFSIZE)) << strerror(errno);
leak(fd);
- free(oldbuf);
- free(oldcontents);
+ delete[] oldbuf;
+ delete[] oldcontents;
}
TEST_F(Write, append_direct_io)
@@ -659,7 +657,7 @@
const char RELPATH[] = "some_file.txt";
Sequence seq;
const off_t filesize = 2 * m_maxbcachebuf;
- void *contents;
+ char *contents;
uint64_t ino = 42;
uint64_t attr_valid = 0;
uint64_t attr_valid_nsec = 0;
@@ -668,7 +666,7 @@
int ngetattrs;
ngetattrs = GetParam();
- contents = calloc(1, filesize);
+ contents = new char[filesize]();
EXPECT_LOOKUP(FUSE_ROOT_ID, RELPATH)
.WillRepeatedly(Invoke(
@@ -742,14 +740,12 @@
void *p;
uint64_t offset = 10;
size_t len;
- void *zeros, *expected;
+ char *zeros, *expected;
len = getpagesize();
- zeros = calloc(1, len);
- ASSERT_NE(nullptr, zeros);
- expected = calloc(1, len);
- ASSERT_NE(nullptr, expected);
+ zeros = new char[len]();
+ expected = new char[len]();
memmove((uint8_t*)expected + offset, CONTENTS, bufsize);
expect_lookup(RELPATH, ino, len);
@@ -774,8 +770,8 @@
ASSERT_EQ(0, munmap(p, len)) << strerror(errno);
close(fd); // Write mmap'd data on close
- free(expected);
- free(zeros);
+ delete[] expected;
+ delete[] zeros;
leak(fd);
}
@@ -867,8 +863,7 @@
if (halfbufsize >= m_maxbcachebuf || halfbufsize >= m_maxphys)
GTEST_SKIP() << "Must lower m_maxwrite for this test";
bufsize = halfbufsize * 2;
- contents = (int*)malloc(bufsize);
- ASSERT_NE(nullptr, contents);
+ contents = new int[bufsize / sizeof(int)];
for (int i = 0; i < (int)bufsize / (int)sizeof(i); i++) {
contents[i] = i;
}
@@ -885,7 +880,7 @@
ASSERT_EQ(bufsize, write(fd, contents, bufsize)) << strerror(errno);
leak(fd);
- free(contents);
+ delete[] contents;
}
TEST_F(Write, write_nothing)
@@ -966,15 +961,13 @@
const char RELPATH[] = "some_file.txt";
uint64_t ino = 42;
int i, fd;
- void *wbuf, *wbuf2x;
+ char *wbuf, *wbuf2x;
ssize_t bufsize = m_maxbcachebuf;
off_t filesize = 5 * bufsize;
- wbuf = malloc(bufsize);
- ASSERT_NE(nullptr, wbuf) << strerror(errno);
+ wbuf = new char[bufsize];
memset(wbuf, 'X', bufsize);
- wbuf2x = malloc(2 * bufsize);
- ASSERT_NE(nullptr, wbuf2x) << strerror(errno);
+ wbuf2x = new char[2 * bufsize];
memset(wbuf2x, 'X', 2 * bufsize);
expect_lookup(RELPATH, ino, filesize);
@@ -997,8 +990,8 @@
<< strerror(errno);
}
close(fd);
- free(wbuf2x);
- free(wbuf);
+ delete[] wbuf2x;
+ delete[] wbuf;
}
/*
@@ -1015,12 +1008,11 @@
const char RELPATH[] = "some_file.txt";
uint64_t ino = 42;
int i, fd;
- void *wbuf;
+ char *wbuf;
ssize_t bufsize = m_maxbcachebuf;
off_t filesize = 4 * bufsize;
- wbuf = malloc(bufsize);
- ASSERT_NE(nullptr, wbuf) << strerror(errno);
+ wbuf = new char[bufsize];
memset(wbuf, 'X', bufsize);
expect_lookup(RELPATH, ino, filesize);
@@ -1042,7 +1034,7 @@
<< strerror(errno);
}
close(fd);
- free(wbuf);
+ delete[] wbuf;
}
/*
@@ -1179,11 +1171,11 @@
int fd;
size_t len;
ssize_t bufsize = strlen(CONTENTS);
- void *p, *zeros;
+ char *zeros;
+ void *p;
len = getpagesize();
- zeros = calloc(1, len);
- ASSERT_NE(nullptr, zeros);
+ zeros = new char[len]();
expect_lookup(RELPATH, ino, len);
expect_open(ino, FOPEN_DIRECT_IO, 1);
@@ -1203,7 +1195,7 @@
ASSERT_EQ(0, munmap(p, len)) << strerror(errno);
close(fd); // Write mmap'd data on close
- free(zeros);
+ delete[] zeros;
}
/*
@@ -1252,10 +1244,9 @@
ssize_t bufsize = strlen(CONTENTS0) + 1;
ssize_t fsize = 2 * m_maxbcachebuf;
char readbuf[bufsize];
- void *zeros;
+ char *zeros;
- zeros = calloc(1, m_maxbcachebuf);
- ASSERT_NE(nullptr, zeros);
+ zeros = new char[m_maxbcachebuf]();
expect_lookup(RELPATH, ino, fsize);
expect_open(ino, 0, 1);
@@ -1282,7 +1273,7 @@
ASSERT_STREQ(readbuf, CONTENTS0);
leak(fd);
- free(zeros);
+ delete[] zeros;
}
/*
@@ -1298,20 +1289,15 @@
int fd;
off_t bs = m_maxbcachebuf;
ssize_t fsize = 3 * bs;
- void *readbuf, *zeros, *ones, *zeroones, *onezeros;
-
- readbuf = malloc(bs);
- ASSERT_NE(nullptr, readbuf) << strerror(errno);
- zeros = calloc(1, 3 * bs);
- ASSERT_NE(nullptr, zeros);
- ones = calloc(1, 2 * bs);
- ASSERT_NE(nullptr, ones);
+ char *readbuf, *zeros, *ones, *zeroones, *onezeros;
+
+ readbuf = new char[bs];
+ zeros = new char[3 * bs]();
+ ones = new char[2 * bs];
memset(ones, 1, 2 * bs);
- zeroones = calloc(1, bs);
- ASSERT_NE(nullptr, zeroones);
+ zeroones = new char[bs]();
memset((uint8_t*)zeroones + bs / 2, 1, bs / 2);
- onezeros = calloc(1, bs);
- ASSERT_NE(nullptr, onezeros);
+ onezeros = new char[bs]();
memset(onezeros, 1, bs / 2);
expect_lookup(RELPATH, ino, fsize);
@@ -1356,11 +1342,11 @@
EXPECT_EQ(0, memcmp(ones, readbuf, bs / 2));
leak(fd);
- free(zeroones);
- free(onezeros);
- free(ones);
- free(zeros);
- free(readbuf);
+ delete[] zeroones;
+ delete[] onezeros;
+ delete[] ones;
+ delete[] zeros;
+ delete[] readbuf;
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 23, 12:30 PM (11 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16796258
Default Alt Text
D43464.diff (13 KB)
Attached To
Mode
D43464: fusefs: prefer new/delete over malloc/free
Attached
Detach File
Event Timeline
Log In to Comment