openvpn plugin: plug leak on realloc failure
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Sat, 23 Apr 2016 09:35:26 +0000 (11:35 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Sat, 23 Apr 2016 09:35:26 +0000 (11:35 +0200)
[src/openvpn.c:715]: (error) Common realloc mistake: 'vpn_list' nulled but not freed upon failure

src/openvpn.c

index 9490ac8..85760e9 100644 (file)
@@ -712,17 +712,19 @@ static int openvpn_config (const char *key, const char *value)
                temp->version = status_version;
                temp->name = status_name;
 
-               vpn_list = realloc (vpn_list, (vpn_num + 1) * sizeof (*vpn_list));
-               if (vpn_list == NULL)
+               vpn_status_t **tmp_list = realloc (vpn_list, (vpn_num + 1) * sizeof (*vpn_list));
+               if (tmp_list == NULL)
                {
                        char errbuf[1024];
                        ERROR ("openvpn plugin: realloc failed: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
 
+                       sfree (vpn_list);
                        sfree (temp->file);
                        sfree (temp);
                        return (1);
                }
+               vpn_list = tmp_list;
 
                vpn_list[vpn_num] = temp;
                vpn_num++;