Skip to content

Commit a848547

Browse files
authored
Fix a few small leaks by properly freeing the result of g_strsplit (#103189)
* Free the result of g_strsplit in debugger_agent_parse_options * Free the result of g_strsplit in mono_gc_base_init for boehm * Free the result of g_strsplit in mono_main * Free the result of g_strsplit in interp_parse_options * Avoid double free
1 parent e2bc045 commit a848547

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

src/mono/mono/component/debugger-agent.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ debugger_agent_parse_options (char *options)
672672
exit (1);
673673
}
674674
}
675+
g_strfreev (args);
675676

676677
if (agent_config.server && !agent_config.suspend) {
677678
/* Waiting for deferred attachment */

src/mono/mono/metadata/boehm-gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ mono_gc_base_init (void)
142142
}
143143
}
144144
g_free (env);
145+
g_strfreev (opts);
145146
}
146147
}
147148

src/mono/mono/mini/driver.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,8 @@ parse_optimizations (guint32 opt, const char* p, gboolean cpu_opts)
189189
exit (1);
190190
}
191191
}
192-
193-
g_free (arg);
194192
}
195-
g_free (parts);
193+
g_strfreev (parts);
196194

197195
return opt;
198196
}
@@ -2208,15 +2206,13 @@ mono_main (int argc, char* argv[])
22082206
} else if (strncmp (argv [i], "--apply-bindings=", 17) == 0) {
22092207
extra_bindings_config_file = &argv[i][17];
22102208
} else if (strncmp (argv [i], "--aot-path=", 11) == 0) {
2211-
char **split;
2209+
char **split, **ptr;
22122210

22132211
split = g_strsplit (argv [i] + 11, G_SEARCHPATH_SEPARATOR_S, 1000);
2214-
while (*split) {
2215-
char *tmp = *split;
2216-
mono_aot_paths = g_list_append (mono_aot_paths, g_strdup (tmp));
2217-
g_free (tmp);
2218-
split++;
2212+
for (ptr = split; ptr && *ptr; ptr++) {
2213+
mono_aot_paths = g_list_append (mono_aot_paths, g_strdup (*ptr));
22192214
}
2215+
g_strfreev (split);
22202216
} else if (strncmp (argv [i], "--path=", 7) == 0) {
22212217
paths = g_list_append (paths, argv [i] + 7);
22222218
} else if (strncmp (argv [i], "--compile-all=", 14) == 0) {

src/mono/mono/mini/interp/interp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8034,6 +8034,7 @@ interp_parse_options (const char *options)
80348034
}
80358035
}
80368036
}
8037+
g_strfreev (args);
80378038
}
80388039

80398040
/*

0 commit comments

Comments
 (0)