]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
obj_bencher: fix leak in error path
authorSamuel Just <sam.just@inktank.com>
Mon, 1 Oct 2012 22:34:04 +0000 (15:34 -0700)
committerSamuel Just <sam.just@inktank.com>
Mon, 1 Oct 2012 22:41:24 +0000 (15:41 -0700)
CID 717076: Resource leak (RESOURCE_LEAK)At (26): Variable "newContents" going
out of scope leaks the storage it points to.

Signed-off-by: Samuel Just <sam.just@inktank.com>
src/common/obj_bencher.cc

index 766edbed41902ce4627c63c24f31db7c4de244bc..74d54e16c90e0515758d909b0a3da0b5f0dc53b2 100644 (file)
@@ -300,6 +300,7 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) {
   out(cout) << "Maintaining " << concurrentios << " concurrent writes of "
        << data.object_size << " bytes for at least "
        << secondsToRun << " seconds." << std::endl;
+  bufferlist* newContents = 0;
 
   std::string prefix = generate_object_prefix();
   out(cout) << "Object prefix: " << prefix << std::endl;
@@ -349,7 +350,6 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) {
 
   //keep on adding new writes as old ones complete until we've passed minimum time
   int slot;
-  bufferlist* newContents;
 
   //don't need locking for reads because other thread doesn't write
 
@@ -417,6 +417,7 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) {
     delete contents[slot];
     name[slot] = newName;
     contents[slot] = newContents;
+    newContents = 0;
   }
 
   while (data.finished < data.started) {
@@ -486,6 +487,7 @@ int ObjBencher::write_bench(int secondsToRun, int concurrentios) {
   data.done = 1;
   lock.Unlock();
   pthread_join(print_thread, NULL);
+  delete newContents;
   return -5;
 }