ifcfg-rh: fix memleaks in reader

(cherry picked from commit 53796f0beb)
This commit is contained in:
Thomas Haller 2015-02-07 16:54:01 +01:00
parent 856962cea8
commit 273576b01c

View file

@ -540,8 +540,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
char **lines = NULL, **iter; char **lines = NULL, **iter;
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info; GMatchInfo *match_info;
NMIPRoute *route = NULL;
char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
gint64 prefix_int, metric_int; gint64 prefix_int, metric_int;
gboolean success = FALSE; gboolean success = FALSE;
@ -573,6 +571,9 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
/* Iterate through file lines */ /* Iterate through file lines */
lines = g_strsplit_set (contents, "\n\r", -1); lines = g_strsplit_set (contents, "\n\r", -1);
for (iter = lines; iter && *iter; iter++) { for (iter = lines; iter && *iter; iter++) {
gs_free char *next_hop = NULL, *dest = NULL;
char *prefix, *metric;
NMIPRoute *route;
/* Skip empty lines */ /* Skip empty lines */
if (g_regex_match_simple (pattern_empty, *iter, 0, 0)) if (g_regex_match_simple (pattern_empty, *iter, 0, 0))
@ -592,11 +593,10 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
} }
dest = g_match_info_fetch (match_info, 1); dest = g_match_info_fetch (match_info, 1);
if (!strcmp (dest, "default")) if (!strcmp (dest, "default"))
strcpy (dest, "0.0.0.0"); strcpy (dest, "0.0.0.0");
if (!nm_utils_ipaddr_valid (AF_INET, dest)) { if (!nm_utils_ipaddr_valid (AF_INET, dest)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route destination address '%s'", dest); "Invalid IP4 route destination address '%s'", dest);
g_free (dest);
g_match_info_free (match_info); g_match_info_free (match_info);
goto error; goto error;
} }
@ -611,7 +611,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
if (errno || prefix_int <= 0 || prefix_int > 32) { if (errno || prefix_int <= 0 || prefix_int > 32) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route destination prefix '%s'", prefix); "Invalid IP4 route destination prefix '%s'", prefix);
g_free (dest);
g_free (prefix); g_free (prefix);
goto error; goto error;
} }
@ -627,13 +626,10 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
"Invalid IP4 route gateway address '%s'", "Invalid IP4 route gateway address '%s'",
next_hop); next_hop);
g_match_info_free (match_info); g_match_info_free (match_info);
g_free (dest);
g_free (next_hop);
goto error; goto error;
} }
} else { } else {
/* we don't make distinction between missing GATEWAY IP and 0.0.0.0 */ /* we don't make distinction between missing GATEWAY IP and 0.0.0.0 */
next_hop = NULL;
} }
g_match_info_free (match_info); g_match_info_free (match_info);
@ -648,8 +644,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
g_match_info_free (match_info); g_match_info_free (match_info);
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION, g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route metric '%s'", metric); "Invalid IP4 route metric '%s'", metric);
g_free (dest);
g_free (next_hop);
g_free (metric); g_free (metric);
goto error; goto error;
} }
@ -658,13 +652,11 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
g_match_info_free (match_info); g_match_info_free (match_info);
route = nm_ip_route_new (AF_INET, dest, prefix_int, next_hop, metric_int, error); route = nm_ip_route_new (AF_INET, dest, prefix_int, next_hop, metric_int, error);
if (!route) { if (!route)
g_free (dest);
g_free (next_hop);
goto error; goto error;
}
if (!nm_setting_ip_config_add_route (s_ip4, route)) if (!nm_setting_ip_config_add_route (s_ip4, route))
PARSE_WARNING ("duplicate IP4 route"); PARSE_WARNING ("duplicate IP4 route");
nm_ip_route_unref (route);
} }
success = TRUE; success = TRUE;
@ -672,8 +664,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
error: error:
g_free (contents); g_free (contents);
g_strfreev (lines); g_strfreev (lines);
if (route)
nm_ip_route_unref (route);
g_regex_unref (regex_to1); g_regex_unref (regex_to1);
g_regex_unref (regex_to2); g_regex_unref (regex_to2);
g_regex_unref (regex_via); g_regex_unref (regex_via);
@ -749,7 +739,6 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
char **lines = NULL, **iter; char **lines = NULL, **iter;
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric; GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info; GMatchInfo *match_info;
NMIPRoute *route = NULL;
char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL; char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
gint64 prefix_int, metric_int; gint64 prefix_int, metric_int;
gboolean success = FALSE; gboolean success = FALSE;
@ -782,6 +771,7 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
/* Iterate through file lines */ /* Iterate through file lines */
lines = g_strsplit_set (contents, "\n\r", -1); lines = g_strsplit_set (contents, "\n\r", -1);
for (iter = lines; iter && *iter; iter++) { for (iter = lines; iter && *iter; iter++) {
NMIPRoute *route;
/* Skip empty lines */ /* Skip empty lines */
if (g_regex_match_simple (pattern_empty, *iter, 0, 0)) if (g_regex_match_simple (pattern_empty, *iter, 0, 0))
@ -871,6 +861,7 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
goto error; goto error;
if (!nm_setting_ip_config_add_route (s_ip6, route)) if (!nm_setting_ip_config_add_route (s_ip6, route))
PARSE_WARNING ("duplicate IP6 route"); PARSE_WARNING ("duplicate IP6 route");
nm_ip_route_unref (route);
} }
success = TRUE; success = TRUE;
@ -878,8 +869,6 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
error: error:
g_free (contents); g_free (contents);
g_strfreev (lines); g_strfreev (lines);
if (route)
nm_ip_route_unref (route);
g_regex_unref (regex_to1); g_regex_unref (regex_to1);
g_regex_unref (regex_to2); g_regex_unref (regex_to2);
g_regex_unref (regex_via); g_regex_unref (regex_via);
@ -4467,6 +4456,7 @@ make_vlan_setting (shvarFile *ifcfg,
goto error; goto error;
} }
g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, parent, NULL); g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, parent, NULL);
g_clear_pointer (&parent, g_free);
if (svTrueValue (ifcfg, "REORDER_HDR", FALSE)) if (svTrueValue (ifcfg, "REORDER_HDR", FALSE))
vlan_flags |= NM_VLAN_FLAG_REORDER_HEADERS; vlan_flags |= NM_VLAN_FLAG_REORDER_HEADERS;
@ -4485,6 +4475,8 @@ make_vlan_setting (shvarFile *ifcfg,
parse_prio_map_list (s_vlan, ifcfg, "VLAN_INGRESS_PRIORITY_MAP", NM_VLAN_INGRESS_MAP); parse_prio_map_list (s_vlan, ifcfg, "VLAN_INGRESS_PRIORITY_MAP", NM_VLAN_INGRESS_MAP);
parse_prio_map_list (s_vlan, ifcfg, "VLAN_EGRESS_PRIORITY_MAP", NM_VLAN_EGRESS_MAP); parse_prio_map_list (s_vlan, ifcfg, "VLAN_EGRESS_PRIORITY_MAP", NM_VLAN_EGRESS_MAP);
g_free (iface_name);
return (NMSetting *) s_vlan; return (NMSetting *) s_vlan;
error: error:
@ -4658,7 +4650,8 @@ connection_from_file_full (const char *filename,
{ {
NMConnection *connection = NULL; NMConnection *connection = NULL;
shvarFile *parsed; shvarFile *parsed;
char *type, *devtype, *bootproto; gs_free char *type = NULL;
char *devtype, *bootproto;
NMSetting *s_ip4, *s_ip6, *s_port, *s_dcb = NULL; NMSetting *s_ip4, *s_ip6, *s_port, *s_dcb = NULL;
const char *ifcfg_name = NULL; const char *ifcfg_name = NULL;
@ -4702,8 +4695,6 @@ connection_from_file_full (const char *filename,
} }
g_free (bootproto); g_free (bootproto);
type = NULL;
devtype = svGetValue (parsed, "DEVICETYPE", FALSE); devtype = svGetValue (parsed, "DEVICETYPE", FALSE);
if (devtype) { if (devtype) {
if (!strcasecmp (devtype, TYPE_TEAM)) if (!strcasecmp (devtype, TYPE_TEAM))
@ -4791,7 +4782,6 @@ connection_from_file_full (const char *filename,
PARSE_WARNING ("connection type was unrecognized but device was not uniquely identified; device may be managed"); PARSE_WARNING ("connection type was unrecognized but device was not uniquely identified; device may be managed");
goto done; goto done;
} }
g_free (type);
if (!connection) if (!connection)
goto done; goto done;