Skip to content

Commit

Permalink
refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x)
Browse files Browse the repository at this point in the history
Change the few conditional uses of FREE_AND_NULL(x) to be
unconditional. As noted in the standard[1] free(NULL) is perfectly
valid, so we might as well leave this check up to the C library.

1. http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html

Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
avar authored and gitster committed Aug 17, 2018
1 parent 53f9a3e commit ce528de
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
4 changes: 1 addition & 3 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ static void fill_origin_blob(struct diff_options *opt,

static void drop_origin_blob(struct blame_origin *o)
{
if (o->file.ptr) {
FREE_AND_NULL(o->file.ptr);
}
FREE_AND_NULL(o->file.ptr);
}

/*
Expand Down
4 changes: 1 addition & 3 deletions branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
tracking->remote = remote->name;
} else {
free(tracking->spec.src);
if (tracking->src) {
FREE_AND_NULL(tracking->src);
}
FREE_AND_NULL(tracking->src);
}
tracking->spec.src = NULL;
}
Expand Down
4 changes: 1 addition & 3 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -2418,9 +2418,7 @@ void release_http_object_request(struct http_object_request *freq)
close(freq->localfile);
freq->localfile = -1;
}
if (freq->url != NULL) {
FREE_AND_NULL(freq->url);
}
FREE_AND_NULL(freq->url);
if (freq->slot != NULL) {
freq->slot->callback_func = NULL;
freq->slot->callback_data = NULL;
Expand Down
4 changes: 1 addition & 3 deletions tree-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,7 @@ struct combine_diff_path *diff_tree_paths(
* free pre-allocated last element, if any
* (see path_appendnew() for details about why)
*/
if (p->next) {
FREE_AND_NULL(p->next);
}
FREE_AND_NULL(p->next);

return p;
}
Expand Down

0 comments on commit ce528de

Please sign in to comment.