From ec45bbe5f1921c6553fbf9c0c76b358b0403c22d Mon Sep 17 00:00:00 2001 From: Saurav Sachidanand Date: Mon, 20 Mar 2017 17:38:28 +0000 Subject: util: Use g_malloc/g_free in envlist.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change malloc/strdup/free to g_malloc/g_strdup/g_free in util/envlist.c. Remove NULL checks for pointers returned from g_malloc and g_strdup as they exit in case of failure. Also, update calls to envlist_create to reflect this. Free array and array contents returned by envlist_to_environ using g_free in bsd-user/main.c and linux-user/main.c. Update comments to reflect change in semantics. Signed-off-by: Saurav Sachidanand Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Michael Tokarev --- bsd-user/main.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'bsd-user') diff --git a/bsd-user/main.c b/bsd-user/main.c index 714a692..04f95dd 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -744,10 +744,7 @@ int main(int argc, char **argv) qemu_init_cpu_list(); module_call_init(MODULE_INIT_QOM); - if ((envlist = envlist_create()) == NULL) { - (void) fprintf(stderr, "Unable to allocate envlist\n"); - exit(1); - } + envlist = envlist_create(); /* add current environment into the list */ for (wrk = environ; *wrk != NULL; wrk++) { @@ -785,10 +782,7 @@ int main(int argc, char **argv) usage(); } else if (!strcmp(r, "ignore-environment")) { envlist_free(envlist); - if ((envlist = envlist_create()) == NULL) { - (void) fprintf(stderr, "Unable to allocate envlist\n"); - exit(1); - } + envlist = envlist_create(); } else if (!strcmp(r, "U")) { r = argv[optind++]; if (envlist_unsetenv(envlist, r) != 0) @@ -956,10 +950,10 @@ int main(int argc, char **argv) } for (wrk = target_environ; *wrk; wrk++) { - free(*wrk); + g_free(*wrk); } - free(target_environ); + g_free(target_environ); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { qemu_log("guest_base 0x%lx\n", guest_base); -- cgit v1.1