qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sarah Khan <sarahjmi07@gmail.com>
To: qemu-devel@nongnu.org, famz@redhat.com
Cc: Sarah Khan <sarahjmi07@gmail.com>
Subject: [Qemu-devel] [PATCH][Outreachy]
Date: Sat,  5 Mar 2016 12:15:18 +0530	[thread overview]
Message-ID: <1457160318-5348-1-git-send-email-sarahjmi07@gmail.com> (raw)

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 <sarahjmi07@gmail.com>

----------
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

             reply	other threads:[~2016-03-05  6:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-05  6:45 Sarah Khan [this message]
2016-03-05 18:04 ` [Qemu-devel] [PATCH][Outreachy] Paolo Bonzini
2016-03-06  8:18 ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1457160318-5348-1-git-send-email-sarahjmi07@gmail.com \
    --to=sarahjmi07@gmail.com \
    --cc=famz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).