git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] avoid NULL dereference on failed malloc

From
Jim Meyering <jim@meyering.net>
Date
Jun 14, 2009, 19:46 UTC
Message-ID
<87hbyioayl.fsf@meyering.net>
* builtin-remote.c (get_one_entry): Use xmalloc, not malloc.
Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 builtin-remote.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 709f8a6..406fb85 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -1282,7 +1282,7 @@ static int get_one_entry(struct remote *remote, void *priv)

 	if (remote->url_nr > 0) {
 		utilp = &(string_list_append(remote->name, list)->util);
-		*utilp = malloc(strlen(remote->url[0])+strlen(" (fetch)")+1);
+		*utilp = xmalloc(strlen(remote->url[0])+strlen(" (fetch)")+1);
 		strcpy((char *) *utilp, remote->url[0]);
 		strcat((char *) *utilp, " (fetch)");
 	} else
@@ -1297,7 +1297,7 @@ static int get_one_entry(struct remote *remote, void *priv)
 	for (i = 0; i < url_nr; i++)
 	{
 		utilp = &(string_list_append(remote->name, list)->util);
-		*utilp = malloc(strlen(url[i])+strlen(" (push)")+1);
+		*utilp = xmalloc(strlen(url[i])+strlen(" (push)")+1);
 		strcpy((char *) *utilp, url[i]);
 		strcat((char *) *utilp, " (push)");
 	}
--
1.6.3.2.406.gd6a466
Next: Michael J Gruber
Message 1 of 9 in “avoid NULL dereference on failed malloc”
  1. avoid NULL dereference on failed mallocJim Meyering, Jun 14, 2009
  2. Michael J GruberJun 15, 2009
  3. builtin-remote: (get_one_entry): use strbufBert Wesarg, Jun 15, 2009
  4. Michael J GruberJun 16, 2009
  5. Bert WesargJun 16, 2009
  6. Michael J GruberJun 16, 2009
  7. builtin-remote: (get_one_entry): use strbufBert Wesarg, Jun 22, 2009
  8. Jeff KingJun 22, 2009
  9. builtin-remote: (get_one_entry): use strbufBert Wesarg, Jun 22, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.