]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Fix memory leak in table.cc
authorMayank Agarwal <amayank@fb.com>
Mon, 2 Sep 2013 22:17:03 +0000 (15:17 -0700)
committerMayank Agarwal <amayank@fb.com>
Tue, 3 Sep 2013 05:13:29 +0000 (22:13 -0700)
Summary:
In InternalGet, BlockReader returns an Iterator which is legitimately freed at the end of the 'else' scope. BUT there is a break statement in between and must be freed there too!
The best solution would be to move to unique_ptr and let it handle. Changed it to a unique_ptr.

Test Plan: valgrind ./db_test;make all check

Reviewers: dhruba, haobo

Reviewed By: dhruba

CC: leveldb
Differential Revision: https://reviews.facebook.net/D12681

table/table.cc

index f2b80cbbc35185f93cf0f1041852f44acaaed6e2..d2d198fb813bafe1ef57ee9aadac305c267cb628 100644 (file)
@@ -421,8 +421,8 @@ Status Table::InternalGet(const ReadOptions& options, const Slice& k,
       break;
     } else {
       bool didIO = false;
-      Iterator* block_iter = BlockReader(this, options, iiter->value(),
-                                         &didIO);
+      std::unique_ptr<Iterator> block_iter(
+        BlockReader(this, options, iiter->value(), &didIO));
 
       if (options.read_tier && block_iter->status().IsIncomplete()) {
         // couldn't get block from block_cache
@@ -440,7 +440,6 @@ Status Table::InternalGet(const ReadOptions& options, const Slice& k,
         }
       }
       s = block_iter->status();
-      delete block_iter;
     }
   }
   if (s.ok()) {