From 8a870858f0bb1170ce6551e5d50f8c8834700236 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 8 Jul 2017 20:25:12 +0800 Subject: [PATCH] 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 --- src/test/librgw_file_nfsns.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 */); } } -- 2.47.3