From: Kefu Chai Date: Sat, 8 Jul 2017 12:25:12 +0000 (+0800) Subject: test/ceph_test_librgw_file_nfsns: always free allocated memory X-Git-Tag: v12.1.1~80^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F16227%2Fhead;p=ceph.git test/ceph_test_librgw_file_nfsns: always free allocated memory use unique_ptr to manage allocated memory, so we can free it even if the test fails. this silences the warnings like: Potential leak of memory pointed to by 'buf2' Signed-off-by: Kefu Chai --- diff --git a/src/test/librgw_file_nfsns.cc b/src/test/librgw_file_nfsns.cc index 1731491ba720..347aee4c6fb3 100644 --- a/src/test/librgw_file_nfsns.cc +++ b/src/test/librgw_file_nfsns.cc @@ -24,6 +24,7 @@ #include "rgw/rgw_lib_frontend.h" // direct requests #include "gtest/gtest.h" +#include "common/backport14.h" #include "common/ceph_argparse.h" #include "common/debug.h" #include "global/global_init.h" @@ -737,22 +738,21 @@ TEST(LibRGW, READF_DIRS1) { ofstream of; of.open(readf_out_name, ios::out|ios::app|ios::binary); int bufsz = 1024 * 1024 * sizeof(char); - char *buffer = (char*) malloc(bufsz); + auto buffer = ceph::make_unique(bufsz); uint64_t offset = 0; uint64_t length = bufsz; for (int ix = 0; ix < 6; ++ix) { size_t nread = 0; - memset(buffer, 0, length); // XXX - rc = rgw_read(fs, fobj.fh, offset, length, &nread, buffer, + memset(buffer.get(), 0, length); // XXX + rc = rgw_read(fs, fobj.fh, offset, length, &nread, buffer.get(), RGW_READ_FLAG_NONE); ASSERT_EQ(rc, 0); ASSERT_EQ(nread, length); - of.write(buffer, length); + of.write(buffer.get(), length); offset += nread; } of.close(); - free(buffer); rgw_fh_rele(fs, fobj.fh, 0 /* flags */); } }