From: Vincent Bernat Date: Mon, 23 Mar 2015 20:35:03 +0000 (+0100) Subject: style: remove `if (...) free(...)` pattern X-Git-Tag: 0.7.14~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=81b171f473218aecf94b601d03bff2be7705c58d;p=thirdparty%2Flldpd.git style: remove `if (...) free(...)` pattern Using the following Coccinelle patch: @@ expression ptr; @@ - if (ptr) { - free(ptr); - } + free(ptr); @@ expression ptr; @@ - if (ptr) free(ptr); + free(ptr); @@ expression ptr; @@ - if (ptr != NULL) { - free(ptr); - } + free(ptr); @@ expression ptr; @@ - if (ptr != NULL) free(ptr); + free(ptr); --- diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index 116a27f2..7b43a03a 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -1905,7 +1905,7 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, case 0: /* Disabling */ case LLDP_MED_LOCFORMAT_COORD: mloc->location->format = value; - if (mloc->location->data) free(mloc->location->data); + free(mloc->location->data); mloc->location->data = calloc(1, 16); if (mloc->location->data == NULL) { mloc->location->data_len = 0; @@ -1916,7 +1916,7 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, return atom; case LLDP_MED_LOCFORMAT_CIVIC: mloc->location->format = value; - if (mloc->location->data) free(mloc->location->data); + free(mloc->location->data); mloc->location->data = calloc(1, 4); if (mloc->location->data == NULL) { mloc->location->data_len = 0; @@ -1931,7 +1931,7 @@ _lldpctl_atom_set_int_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, return atom; case LLDP_MED_LOCFORMAT_ELIN: mloc->location->format = value; - if (mloc->location->data) free(mloc->location->data); + free(mloc->location->data); mloc->location->data = NULL; mloc->location->data_len = 0; return atom; @@ -2124,7 +2124,7 @@ _lldpctl_atom_set_str_med_location(lldpctl_atom_t *atom, lldpctl_key_t key, case lldpctl_k_med_location_elin: if (!value) goto bad; if (mloc->location->format != LLDP_MED_LOCFORMAT_ELIN) goto bad; - if (mloc->location->data) free(mloc->location->data); + free(mloc->location->data); mloc->location->data = calloc(1, strlen(value)); if (mloc->location->data == NULL) { mloc->location->data_len = 0; diff --git a/tests/check_snmp.c b/tests/check_snmp.c index 86cc798a..d5b6f072 100644 --- a/tests/check_snmp.c +++ b/tests/check_snmp.c @@ -345,7 +345,7 @@ snmp_oidrepr(oid *name, size_t namelen) int i; current = (current + 1)%4; - if (buffer[current]) free(buffer[current]); buffer[current] = NULL; + free(buffer[current]); buffer[current] = NULL; for (i = 0; i < namelen; i++) { /* Not very efficient... */ @@ -356,7 +356,7 @@ snmp_oidrepr(oid *name, size_t namelen) buffer[current] = NULL; return NULL; } - if (buffer[current]) free(buffer[current]); + free(buffer[current]); buffer[current] = newbuffer; } return buffer[current++]; @@ -851,7 +851,7 @@ tohex(char *str, size_t len) { static char *hex[] = { NULL, NULL }; static int which = 0; - if (hex[which]) free(hex[which]); hex[which] = NULL; + free(hex[which]); hex[which] = NULL; hex[which] = malloc(len * 3 + 1); fail_unless(hex[which] != NULL, "Not enough memory?"); for (int i = 0; i < len; i++)