util: Use g_malloc/g_free in envlist.c
PATCH v4 1/1 util: Use g_malloc/g_free in envlist.c
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.
--- bsd-user/main.c | 14 ++++---------- linux-user/main.c | 9 +++------ util/envlist.c | 47 +++++++++++++++++++---------------------------- 3 files changed, 26 insertions(+), 44 deletions(-)
bsd-user/main.c +4 -10
@@ -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);
linux-user/main.c +3 -6
@@ -4229,10 +4229,7 @@ int main(int argc, char **argv, char **envp)qemu_init_cpu_list ();module_call_init (MODULE_INIT_QOM ); -if ((envlist =envlist_create ()) ==NULL ) { - (void )fprintf (stderr,"Unable to allocate envlist\n" ); -exit (EXIT_FAILURE ); - } + envlist =envlist_create ();/* add current environment into the list */ for (wrk = environ; *wrk !=NULL ; wrk++) {
@@ -4429,10 +4426,10 @@ int main(int argc, char **argv, char **envp) }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);
util/envlist.c +19 -28
111 lines not on this page · raw message
Signature · 1 line
2.12.0
Quoted 7 lines · Saurav Sachidanand
Change malloc/strdup/free to g_malloc/g_strdup/g_free in
util/envlist.c.Remove NULL checks for pointers returned from
g_mallocandg_strdupas they exit in case of failure. Also, update calls toenvlist_createto reflect this.
Quoted 5 lines
Free array and array contents returned by
envlist_to_environusingg_freeinbsd-user/main.candlinux-user/main.c.Update comments to reflect change in semantics.
---
Sorry, forgot to sign it.