diff options
author | Alex Gorrod <alexg@wiredtiger.com> | 2013-11-17 12:43:24 +1100 |
---|---|---|
committer | Alex Gorrod <alexg@wiredtiger.com> | 2013-11-17 12:43:24 +1100 |
commit | 1ba5e963a2a90a1897ab8d5f2980af0608d6053f (patch) | |
tree | 664d2e13d4dc7bc622ca04d89868f4385e2c9059 | |
parent | e729c5a6bce568d9e24385ec68767bc316ccac82 (diff) | |
download | mongo-1ba5e963a2a90a1897ab8d5f2980af0608d6053f.tar.gz |
Tidy error path in LSM truncation.
Based on Coverity resource leak ID 1129049:
Resource leak (RESOURCE_LEAK)
leaked_storage: Variable "chunk" going out of scope leaks the
storage it points to.
-rw-r--r-- | src/lsm/lsm_tree.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/lsm/lsm_tree.c b/src/lsm/lsm_tree.c index e7d5923829b..9131cf0fcc7 100644 --- a/src/lsm/lsm_tree.c +++ b/src/lsm/lsm_tree.c @@ -790,6 +790,7 @@ __wt_lsm_tree_truncate( int locked; WT_UNUSED(cfg); + chunk = NULL; locked = 0; /* Get the LSM tree. */ @@ -820,12 +821,19 @@ __wt_lsm_tree_truncate( err: if (locked) WT_TRET(__wt_lsm_tree_unlock(session, lsm_tree)); - /* - * Don't discard the LSM tree structure unless there has been an - * error. The handle remains valid for future operations. - */ - if (ret != 0) + if (ret != 0) { + if (chunk != NULL) { + (void)__wt_schema_drop(session, chunk->uri, NULL); + __wt_free(session, chunk); + } + /* + * Discard the LSM tree structure on error. This will force the + * LSM tree to be re-opened the next time it is accessed and + * the last good version of the metadata will be used. + * Resulting in a valid (un-truncated) tree. + */ WT_TRET(__lsm_tree_discard(session, lsm_tree)); + } return (ret); } |