]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
style: remove `if (...) free(...)` pattern
authorVincent Bernat <vincent@bernat.im>
Mon, 23 Mar 2015 20:35:03 +0000 (21:35 +0100)
committerVincent Bernat <vincent@bernat.im>
Mon, 23 Mar 2015 20:35:03 +0000 (21:35 +0100)
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);

src/lib/atom-private.c
tests/check_snmp.c

index 116a27f2f5ce70fdfa7ed2ab579f86bf2c393c6b..7b43a03af56d597423d1f6f5e842982780d71799 100644 (file)
@@ -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;
index 86cc798a547ae76739330cf49634f60f96a1721d..d5b6f0728068ffeaf095af3a040d5de691b89ad1 100644 (file)
@@ -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++)