Received: from eggs.gnu.org ([2001:4830:134:3::10]:56630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ac5yG-0002Gz-MW for qemu-devel@nongnu.org; Sat, 05 Mar 2016 01:45:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ac5y7-00015O-Kb for qemu-devel@nongnu.org; Sat, 05 Mar 2016 01:45:48 -0500 Received: from mail-pa0-x235.google.com ([2607:f8b0:400e:c03::235]:35996) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ac5y7-00015K-7B for qemu-devel@nongnu.org; Sat, 05 Mar 2016 01:45:39 -0500 Received: by mail-pa0-x235.google.com with SMTP id fi3so44990240pac.3 for ; Fri, 04 Mar 2016 22:45:39 -0800 (PST) From: Sarah Khan Date: Sat, 5 Mar 2016 12:15:18 +0530 Message-Id: <1457160318-5348-1-git-send-email-sarahjmi07@gmail.com> Subject: [Qemu-devel] [PATCH][Outreachy] List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, famz@redhat.com Cc: Sarah Khan util/envlist.c:This patch replaces malloc with g_malloc This replacement was suggested as part of the bite-sized tasks. Signed-off-by: Sarah Khan ---------- diff --git a/util/envlist.c b/util/envlist.c index e86857e..0324fe2 100644 --- a/util/envlist.c +++ b/util/envlist.c @@ -25,7 +25,7 @@ envlist_create(void) { envlist_t *envlist; - if ((envlist = malloc(sizeof (*envlist))) == NULL) + if ((envlist = g_malloc(sizeof (*envlist))) == NULL) return (NULL); QLIST_INIT(&envlist->el_entries); @@ -48,10 +48,10 @@ envlist_free(envlist_t *envlist) entry = envlist->el_entries.lh_first; QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); } - free(envlist); + g_free(envlist); } /* @@ -155,16 +155,16 @@ envlist_setenv(envlist_t *envlist, const char *env) if (entry != NULL) { QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); } else { envlist->el_count++; } - if ((entry = malloc(sizeof (*entry))) == NULL) + if ((entry = g_malloc(sizeof (*entry))) == NULL) return (errno); if ((entry->ev_var = strdup(env)) == NULL) { - free(entry); + g_free(entry); return (errno); } QLIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link); @@ -201,8 +201,8 @@ envlist_unsetenv(envlist_t *envlist, const char *env) } if (entry != NULL) { QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); envlist->el_count--; } @@ -225,7 +225,7 @@ envlist_to_environ(const envlist_t *envlist, size_t *count) struct envlist_entry *entry; char **env, **penv; - penv = env = malloc((envlist->el_count + 1) * sizeof (char *)); + penv = env = g_malloc((envlist->el_count + 1) * sizeof (char *)); if (env == NULL) return (NULL); --- util/envlist.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/util/envlist.c b/util/envlist.c index e86857e..0324fe2 100644 --- a/util/envlist.c +++ b/util/envlist.c @@ -25,7 +25,7 @@ envlist_create(void) { envlist_t *envlist; - if ((envlist = malloc(sizeof (*envlist))) == NULL) + if ((envlist = g_malloc(sizeof (*envlist))) == NULL) return (NULL); QLIST_INIT(&envlist->el_entries); @@ -48,10 +48,10 @@ envlist_free(envlist_t *envlist) entry = envlist->el_entries.lh_first; QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); } - free(envlist); + g_free(envlist); } /* @@ -155,16 +155,16 @@ envlist_setenv(envlist_t *envlist, const char *env) if (entry != NULL) { QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); } else { envlist->el_count++; } - if ((entry = malloc(sizeof (*entry))) == NULL) + if ((entry = g_malloc(sizeof (*entry))) == NULL) return (errno); if ((entry->ev_var = strdup(env)) == NULL) { - free(entry); + g_free(entry); return (errno); } QLIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link); @@ -201,8 +201,8 @@ envlist_unsetenv(envlist_t *envlist, const char *env) } if (entry != NULL) { QLIST_REMOVE(entry, ev_link); - free((char *)entry->ev_var); - free(entry); + g_free((char *)entry->ev_var); + g_free(entry); envlist->el_count--; } @@ -225,7 +225,7 @@ envlist_to_environ(const envlist_t *envlist, size_t *count) struct envlist_entry *entry; char **env, **penv; - penv = env = malloc((envlist->el_count + 1) * sizeof (char *)); + penv = env = g_malloc((envlist->el_count + 1) * sizeof (char *)); if (env == NULL) return (NULL); -- 1.9.1