diff options
author | Keith Bostic <keith@wiredtiger.com> | 2016-03-16 13:07:59 -0400 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2016-03-16 13:07:59 -0400 |
commit | c82bed6dc12e6819e73203c034191bf8a1335204 (patch) | |
tree | 3d9b00fae3894b2af6dc4e328c4c32ff525e5099 | |
parent | 4ec307dce22f6162f3ffa7497326f743b483d7d2 (diff) | |
download | mongo-c82bed6dc12e6819e73203c034191bf8a1335204.tar.gz |
WT-2494: review calls to __wt_free, plus minor bug in an error path.
Remove checks for "pointer != NULL" before calling __wt_free(), they're
not needed.
In __wt_async_op_init(), don't bother clearing the pointer values after
calling __wt_free(), they get cleared by __wt_free().
In __lsm_tree_set_name(), don't leave the tree without a name, by freeing
the name and then failing to allocate room for the new one.
In __ckpt_last_name(), don't free the wrong pointer in the error path.
-rw-r--r-- | src/async/async_op.c | 12 | ||||
-rw-r--r-- | src/btree/bt_discard.c | 3 | ||||
-rw-r--r-- | src/btree/bt_read.c | 6 | ||||
-rw-r--r-- | src/btree/bt_slvg.c | 6 | ||||
-rw-r--r-- | src/btree/bt_split.c | 3 | ||||
-rw-r--r-- | src/conn/conn_open.c | 6 | ||||
-rw-r--r-- | src/cursor/cur_join.c | 3 | ||||
-rw-r--r-- | src/log/log.c | 6 | ||||
-rw-r--r-- | src/lsm/lsm_tree.c | 13 | ||||
-rw-r--r-- | src/meta/meta_ckpt.c | 5 | ||||
-rw-r--r-- | src/os_posix/os_stdio.c | 3 | ||||
-rw-r--r-- | src/packing/pack_stream.c | 3 | ||||
-rw-r--r-- | src/schema/schema_open.c | 3 |
13 files changed, 27 insertions, 45 deletions
diff --git a/src/async/async_op.c b/src/async/async_op.c index 130c704757b..970c33c3360 100644 --- a/src/async/async_op.c +++ b/src/async/async_op.c @@ -349,14 +349,8 @@ __wt_async_op_init(WT_SESSION_IMPL *session) WT_ERR(__async_op_init(conn, op, i)); } return (0); -err: - if (async->async_ops != NULL) { - __wt_free(session, async->async_ops); - async->async_ops = NULL; - } - if (async->async_queue != NULL) { - __wt_free(session, async->async_queue); - async->async_queue = NULL; - } + +err: __wt_free(session, async->async_ops); + __wt_free(session, async->async_queue); return (ret); } diff --git a/src/btree/bt_discard.c b/src/btree/bt_discard.c index 795111d53f9..1f739c9572e 100644 --- a/src/btree/bt_discard.c +++ b/src/btree/bt_discard.c @@ -337,8 +337,7 @@ __free_page_row_leaf(WT_SESSION_IMPL *session, WT_PAGE *page) copy = WT_ROW_KEY_COPY(rip); (void)__wt_row_leaf_key_info( page, copy, &ikey, NULL, NULL, NULL); - if (ikey != NULL) - __wt_free(session, ikey); + __wt_free(session, ikey); } /* diff --git a/src/btree/bt_read.c b/src/btree/bt_read.c index f80eb09153c..5cf6a9bf2bc 100644 --- a/src/btree/bt_read.c +++ b/src/btree/bt_read.c @@ -281,10 +281,8 @@ err: WT_TRET(__wt_las_cursor_close(session, &cursor, session_flags)); * On error, upd points to a single unlinked WT_UPDATE structure, * first_upd points to a list. */ - if (upd != NULL) - __wt_free(session, upd); - if (first_upd != NULL) - __wt_free_update_list(session, first_upd); + __wt_free(session, upd); + __wt_free_update_list(session, first_upd); __wt_scr_free(session, ¤t_key); __wt_scr_free(session, &las_addr); diff --git a/src/btree/bt_slvg.c b/src/btree/bt_slvg.c index 8d78bda79fb..0e064d306b6 100644 --- a/src/btree/bt_slvg.c +++ b/src/btree/bt_slvg.c @@ -1206,8 +1206,7 @@ __slvg_col_build_internal( __wt_root_ref_init(&ss->root_ref, page, true); if (0) { -err: if (addr != NULL) - __wt_free(session, addr); +err: __wt_free(session, addr); __wt_page_out(session, &page); } return (ret); @@ -1868,8 +1867,7 @@ __slvg_row_build_internal( __wt_root_ref_init(&ss->root_ref, page, false); if (0) { -err: if (addr != NULL) - __wt_free(session, addr); +err: __wt_free(session, addr); __wt_page_out(session, &page); } return (ret); diff --git a/src/btree/bt_split.c b/src/btree/bt_split.c index 3dea03316ce..4f16a290958 100644 --- a/src/btree/bt_split.c +++ b/src/btree/bt_split.c @@ -151,8 +151,7 @@ __wt_split_stash_discard_all( for (i = 0, stash = session->split_stash; i < session->split_stash_cnt; ++i, ++stash) - if (stash->p != NULL) - __wt_free(session_safe, stash->p); + __wt_free(session_safe, stash->p); __wt_free(session_safe, session->split_stash); session->split_stash_cnt = session->split_stash_alloc = 0; diff --git a/src/conn/conn_open.c b/src/conn/conn_open.c index 58577b4587d..aff422654d7 100644 --- a/src/conn/conn_open.c +++ b/src/conn/conn_open.c @@ -210,10 +210,8 @@ __wt_connection_close(WT_CONNECTION_IMPL *conn) /* * If hash arrays were allocated, free them now. */ - if (s->dhhash != NULL) - __wt_free(session, s->dhhash); - if (s->tablehash != NULL) - __wt_free(session, s->tablehash); + __wt_free(session, s->dhhash); + __wt_free(session, s->tablehash); __wt_free(session, s->hazard); } diff --git a/src/cursor/cur_join.c b/src/cursor/cur_join.c index 8f69f748f9d..33e4f2580b6 100644 --- a/src/cursor/cur_join.c +++ b/src/cursor/cur_join.c @@ -1127,8 +1127,7 @@ __wt_curjoin_join(WT_SESSION_IMPL *session, WT_CURSOR_JOIN *cjoin, cindex->iface.key_format); } -err: if (main_uri != NULL) - __wt_free(session, main_uri); +err: __wt_free(session, main_uri); return (ret); } diff --git a/src/log/log.c b/src/log/log.c index 0b47308cfd8..e41073299a8 100644 --- a/src/log/log.c +++ b/src/log/log.c @@ -1252,10 +1252,8 @@ __log_has_hole(WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t offset, bool *hole) } } -err: if (buf != NULL) - __wt_free(session, buf); - if (zerobuf != NULL) - __wt_free(session, zerobuf); +err: __wt_free(session, buf); + __wt_free(session, zerobuf); return (ret); } diff --git a/src/lsm/lsm_tree.c b/src/lsm/lsm_tree.c index 45994bae42b..70ac912f333 100644 --- a/src/lsm/lsm_tree.c +++ b/src/lsm/lsm_tree.c @@ -157,9 +157,12 @@ static int __lsm_tree_set_name(WT_SESSION_IMPL *session, WT_LSM_TREE *lsm_tree, const char *uri) { - if (lsm_tree->name != NULL) - __wt_free(session, lsm_tree->name); - WT_RET(__wt_strdup(session, uri, &lsm_tree->name)); + void *p; + + WT_RET(__wt_strdup(session, uri, &p)); + + __wt_free(session, lsm_tree->name); + lsm_tree->name = p; lsm_tree->filename = lsm_tree->name + strlen("lsm:"); return (0); } @@ -950,8 +953,8 @@ __wt_lsm_tree_rename(WT_SESSION_IMPL *session, err: if (locked) WT_TRET(__wt_lsm_tree_writeunlock(session, lsm_tree)); - if (old != NULL) - __wt_free(session, old); + __wt_free(session, old); + /* * Discard this LSM tree structure. The first operation on the renamed * tree will create a new one. diff --git a/src/meta/meta_ckpt.c b/src/meta/meta_ckpt.c index df4cd2cb4d6..0a864432daf 100644 --- a/src/meta/meta_ckpt.c +++ b/src/meta/meta_ckpt.c @@ -212,8 +212,7 @@ __ckpt_last_name( if (found && a.val < found) continue; - if (*namep != NULL) - __wt_free(session, *namep); + __wt_free(session, *namep); WT_ERR(__wt_strndup(session, k.str, k.len, namep)); found = a.val; } @@ -221,7 +220,7 @@ __ckpt_last_name( ret = WT_NOTFOUND; if (0) { -err: __wt_free(session, namep); +err: __wt_free(session, *namep); } return (ret); } diff --git a/src/os_posix/os_stdio.c b/src/os_posix/os_stdio.c index 7ab107eda1e..65a0f40a659 100644 --- a/src/os_posix/os_stdio.c +++ b/src/os_posix/os_stdio.c @@ -46,8 +46,7 @@ __wt_fopen(WT_SESSION_IMPL *session, if (*fpp == NULL) ret = __wt_errno(); - if (pathbuf != NULL) - __wt_free(session, pathbuf); + __wt_free(session, pathbuf); if (ret == 0) return (0); diff --git a/src/packing/pack_stream.c b/src/packing/pack_stream.c index 5716c31a9c2..1393eb9a9c1 100644 --- a/src/packing/pack_stream.c +++ b/src/packing/pack_stream.c @@ -65,8 +65,7 @@ wiredtiger_pack_close(WT_PACK_STREAM *ps, size_t *usedp) if (usedp != NULL) *usedp = WT_PTRDIFF(ps->p, ps->start); - if (ps != NULL) - __wt_free(ps->pack.session, ps); + __wt_free(ps->pack.session, ps); return (0); } diff --git a/src/schema/schema_open.c b/src/schema/schema_open.c index 49318f80959..e7ce4e42498 100644 --- a/src/schema/schema_open.c +++ b/src/schema/schema_open.c @@ -109,8 +109,7 @@ __wt_schema_open_colgroups(WT_SESSION_IMPL *session, WT_TABLE *table) err: __wt_scr_free(session, &buf); __wt_schema_destroy_colgroup(session, &colgroup); - if (cgconfig != NULL) - __wt_free(session, cgconfig); + __wt_free(session, cgconfig); return (ret); } |