Skip to content

Commit ce528de

Browse files
avargitster
authored andcommitted
refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x)
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]>
1 parent 53f9a3e commit ce528de

File tree

4 files changed

+4
-12
lines changed

4 files changed

+4
-12
lines changed

blame.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,7 @@ static void fill_origin_blob(struct diff_options *opt,
313313

314314
static void drop_origin_blob(struct blame_origin *o)
315315
{
316-
if (o->file.ptr) {
317-
FREE_AND_NULL(o->file.ptr);
318-
}
316+
FREE_AND_NULL(o->file.ptr);
319317
}
320318

321319
/*

branch.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
2525
tracking->remote = remote->name;
2626
} else {
2727
free(tracking->spec.src);
28-
if (tracking->src) {
29-
FREE_AND_NULL(tracking->src);
30-
}
28+
FREE_AND_NULL(tracking->src);
3129
}
3230
tracking->spec.src = NULL;
3331
}

http.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,9 +2418,7 @@ void release_http_object_request(struct http_object_request *freq)
24182418
close(freq->localfile);
24192419
freq->localfile = -1;
24202420
}
2421-
if (freq->url != NULL) {
2422-
FREE_AND_NULL(freq->url);
2423-
}
2421+
FREE_AND_NULL(freq->url);
24242422
if (freq->slot != NULL) {
24252423
freq->slot->callback_func = NULL;
24262424
freq->slot->callback_data = NULL;

tree-diff.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,7 @@ struct combine_diff_path *diff_tree_paths(
557557
* free pre-allocated last element, if any
558558
* (see path_appendnew() for details about why)
559559
*/
560-
if (p->next) {
561-
FREE_AND_NULL(p->next);
562-
}
560+
FREE_AND_NULL(p->next);
563561

564562
return p;
565563
}

0 commit comments

Comments
 (0)