chiark / gitweb /
networkctl: avoid leak if a field was specified twice
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 7 Mar 2015 19:06:35 +0000 (14:06 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 7 Mar 2015 19:06:35 +0000 (14:06 -0500)
The input data would have to be borked, so this is unlikely to happen,
but since we have a nice helper function to do it properly... why not?

CID #1261390.

src/network/networkctl.c

index 063751376a4a040352d3ba92b5e9e5d05cf583ec..3a6faa273d14c4012ba090aa5db04a65041c18de 100644 (file)
@@ -965,14 +965,14 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
                                         continue;
 
                                 if (streq(a, "_Chassis")) {
                                         continue;
 
                                 if (streq(a, "_Chassis")) {
-                                        chassis = strdup(b);
-                                        if (!chassis)
-                                                return -ENOMEM;
+                                        r = free_and_strdup(&chassis, b);
+                                        if (r < 0)
+                                                return r;
 
                                 } else if (streq(a, "_Port")) {
 
                                 } else if (streq(a, "_Port")) {
-                                        port = strdup(b);
-                                        if (!port)
-                                                return -ENOMEM;
+                                        r = free_and_strdup(&port, b);
+                                        if (r < 0)
+                                                return r;
 
                                 } else if (streq(a, "_TTL")) {
                                         long long unsigned x;
 
                                 } else if (streq(a, "_TTL")) {
                                         long long unsigned x;