git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Rename dynamic memory allocation functions to their "x" version
@ 2008-09-09 18:57 Dotan Barak
  2008-09-10  4:11 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Dotan Barak @ 2008-09-09 18:57 UTC (permalink / raw)
  To: git

In places that the standard malloc/strdup is used without checking
if the allocation was successful, I replaced it to xmalloc/xstrdup
which check the memory allocation result.

Signed-off-by: Dotan Barak <dotanba@gmail.com>

---

diff --git a/builtin-http-fetch.c b/builtin-http-fetch.c
index 3a06248..ea2b689 100644
--- a/builtin-http-fetch.c
+++ b/builtin-http-fetch.c
@@ -53,7 +53,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
 	}
 	url = argv[arg];
 	if (url && url[strlen(url)-1] != '/') {
-		rewritten_url = malloc(strlen(url)+2);
+		rewritten_url = xmalloc(strlen(url)+2);
 		strcpy(rewritten_url, url);
 		strcat(rewritten_url, "/");
 		url = rewritten_url;
diff --git a/git.c b/git.c
index adf7352..905acc2 100644
--- a/git.c
+++ b/git.c
@@ -364,7 +364,7 @@ static void handle_internal_command(int argc, const char **argv)
 	if (sizeof(ext) > 1) {
 		i = strlen(argv[0]) - strlen(ext);
 		if (i > 0 && !strcmp(argv[0] + i, ext)) {
-			char *argv0 = strdup(argv[0]);
+			char *argv0 = xstrdup(argv[0]);
 			argv[0] = cmd = argv0;
 			argv0[i] = '\0';
 		}
diff --git a/http-push.c b/http-push.c
index 6805288..c9dd9a1 100644
--- a/http-push.c
+++ b/http-push.c
@@ -2237,7 +2237,7 @@ int main(int argc, char **argv)
 	no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
 
 	if (remote->url && remote->url[strlen(remote->url)-1] != '/') {
-		rewritten_url = malloc(strlen(remote->url)+2);
+		rewritten_url = xmalloc(strlen(remote->url)+2);
 		strcpy(rewritten_url, remote->url);
 		strcat(rewritten_url, "/");
 		remote->url = rewritten_url;
diff --git a/http.c b/http.c
index 1108ab4..0788936 100644
--- a/http.c
+++ b/http.c
@@ -402,7 +402,7 @@ static struct fill_chain *fill_cfg = NULL;
 
 void add_fill_function(void *data, int (*fill)(void *))
 {
-	struct fill_chain *new = malloc(sizeof(*new));
+	struct fill_chain *new = xmalloc(sizeof(*new));
 	struct fill_chain **linkp = &fill_cfg;
 	new->data = data;
 	new->fill = fill;
diff --git a/remote.c b/remote.c
index 3ef09a4..3f3c789 100644
--- a/remote.c
+++ b/remote.c
@@ -69,7 +69,7 @@ static const char *alias_url(const char *url)
 	if (!longest)
 		return url;
 
-	ret = malloc(rewrite[longest_i]->baselen +
+	ret = xmalloc(rewrite[longest_i]->baselen +
 		     (strlen(url) - longest->len) + 1);
 	strcpy(ret, rewrite[longest_i]->base);
 	strcpy(ret + rewrite[longest_i]->baselen, url + longest->len);
@@ -152,7 +152,7 @@ static struct branch *make_branch(const char *name, int len)
 		ret->name = xstrndup(name, len);
 	else
 		ret->name = xstrdup(name);
-	refname = malloc(strlen(name) + strlen("refs/heads/") + 1);
+	refname = xmalloc(strlen(name) + strlen("refs/heads/") + 1);
 	strcpy(refname, "refs/heads/");
 	strcpy(refname + strlen("refs/heads/"), ret->name);
 	ret->refname = refname;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Rename dynamic memory allocation functions to their "x" version
  2008-09-09 18:57 [PATCH] Rename dynamic memory allocation functions to their "x" version Dotan Barak
@ 2008-09-10  4:11 ` Junio C Hamano
  2008-09-10  6:02   ` Dotan Barak
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2008-09-10  4:11 UTC (permalink / raw)
  To: Dotan Barak; +Cc: git

Dotan Barak <dotanba@gmail.com> writes:

> In places that the standard malloc/strdup is used without checking
> if the allocation was successful, I replaced it to xmalloc/xstrdup
> which check the memory allocation result.
>
> Signed-off-by: Dotan Barak <dotanba@gmail.com>

Looks good.  Will apply, but I'd retitle it (it is not "rename").

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Rename dynamic memory allocation functions to their "x" version
  2008-09-10  4:11 ` Junio C Hamano
@ 2008-09-10  6:02   ` Dotan Barak
  0 siblings, 0 replies; 3+ messages in thread
From: Dotan Barak @ 2008-09-10  6:02 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Wed, Sep 10, 2008 at 7:11 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Dotan Barak <dotanba@gmail.com> writes:
>
>> In places that the standard malloc/strdup is used without checking
>> if the allocation was successful, I replaced it to xmalloc/xstrdup
>> which check the memory allocation result.
>>
>> Signed-off-by: Dotan Barak <dotanba@gmail.com>
>
> Looks good.  Will apply, but I'd retitle it (it is not "rename").
>
Yes, you are right, i guess "replace" is better ...

Next time..
;)

Dotan

> Thanks.
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-09-10  6:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-09 18:57 [PATCH] Rename dynamic memory allocation functions to their "x" version Dotan Barak
2008-09-10  4:11 ` Junio C Hamano
2008-09-10  6:02   ` Dotan Barak

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