[fastmanifest] remove unneeded if-checks for freeing memory

Summary: `free(..)` can be called with a NULL pointer.  Had no idea.

Test Plan: pass unit tests

Reviewers: lcharignon, wez

Reviewed By: wez

Subscribers: mitrandir, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3250848

Signature: t1:3250848:1462320316:f1c56886a1ffa694ee6d9850b820a3b51cfb8914
This commit is contained in:
Tony Tung 2016-05-03 22:39:13 -07:00
parent 15906f6840
commit 8f990c2a47
4 changed files with 12 additions and 38 deletions

View File

@ -87,15 +87,9 @@ tree_t *alloc_tree() {
return tree; return tree;
fail: fail:
if (shadow_root != NULL) { free(shadow_root);
free(shadow_root); free(real_root);
} free(tree);
if (real_root != NULL) {
free(real_root);
}
if (tree != NULL) {
free(tree);
}
return NULL; return NULL;
} }
@ -114,15 +108,9 @@ void destroy_tree(tree_t *tree) {
if (tree->compacted == false) { if (tree->compacted == false) {
destroy_tree_helper(tree, tree->shadow_root); destroy_tree_helper(tree, tree->shadow_root);
} else { } else {
if (tree->shadow_root != NULL) { free(tree->shadow_root);
free(tree->shadow_root);
tree->shadow_root = NULL;
}
}
if (tree->arena != NULL) {
free(tree->arena);
tree->arena = NULL;
} }
free(tree->arena);
free(tree); free(tree);
} }

View File

@ -110,15 +110,9 @@ tree_t *alloc_tree_with_arena(size_t arena_sz) {
node_t *shadow_root = alloc_node("/", 1, 1); node_t *shadow_root = alloc_node("/", 1, 1);
if (arena == NULL || tree == NULL || shadow_root == NULL) { if (arena == NULL || tree == NULL || shadow_root == NULL) {
if (arena != NULL) { free(arena);
free(arena); free(tree);
} free(shadow_root);
if (tree != NULL) {
free(tree);
}
if (shadow_root != NULL) {
free(shadow_root);
}
return NULL; return NULL;
} }

View File

@ -585,12 +585,9 @@ convert_to_flat_result_t convert_to_flat(tree_t *tree) {
result = convert_to_flat_helper(&state, tree); result = convert_to_flat_helper(&state, tree);
} }
if (state.dirpath_build_buffer != NULL) { free(state.dirpath_build_buffer);
free(state.dirpath_build_buffer);
}
if (state.output_buffer != NULL && if (result != CONVERT_TO_FLAT_OK) {
result != CONVERT_TO_FLAT_OK) {
// free the buffer if any error occurred. // free the buffer if any error occurred.
free(state.output_buffer); free(state.output_buffer);
return (convert_to_flat_result_t) {result, NULL, 0}; return (convert_to_flat_result_t) {result, NULL, 0};

View File

@ -56,13 +56,8 @@ fail:
free(result); free(result);
} }
if (path_records != NULL) { free(path_records);
free(path_records); free(path);
}
if (path != NULL) {
free(path);
}
return NULL; return NULL;
} }