Use xmalloc() and friends to catch allocation failures
Some places use the standard malloc/strdup without checking if the allocation was successful; they should use xmalloc/xstrdup that check the memory allocation result. Signed-off-by: Dotan Barak <dotanba@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dotan Barak committed
Sep 9, 2008 at 21:57 UTC
e8eec71d6e79c176d34dc8fda8780ed4dee447a2
5 files changed
+6
-6
builtin-http-fetch.c
+1
-1
@@ -53,7 +53,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
53
}
54
url = argv[arg];
55
if (url && url[strlen(url)-1] != '/') {
56
- rewritten_url = malloc(strlen(url)+2);
56
+ rewritten_url = xmalloc(strlen(url)+2);
57
strcpy(rewritten_url, url);
58
strcat(rewritten_url, "/");
59
url = rewritten_url;
git.c
+1
-1
@@ -364,7 +364,7 @@ static void handle_internal_command(int argc, const char **argv)
364
if (sizeof(ext) > 1) {
365
i = strlen(argv[0]) - strlen(ext);
366
if (i > 0 && !strcmp(argv[0] + i, ext)) {
367
- char *argv0 = strdup(argv[0]);
367
+ char *argv0 = xstrdup(argv[0]);
368
argv[0] = cmd = argv0;
369
argv0[i] = '\0';
370
}
http-push.c
+1
-1
@@ -2237,7 +2237,7 @@ int main(int argc, char **argv)
2237
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
2238
2239
if (remote->url && remote->url[strlen(remote->url)-1] != '/') {
2240
- rewritten_url = malloc(strlen(remote->url)+2);
2240
+ rewritten_url = xmalloc(strlen(remote->url)+2);
2241
strcpy(rewritten_url, remote->url);
2242
strcat(rewritten_url, "/");
2243
remote->url = rewritten_url;
http.c
+1
-1
@@ -402,7 +402,7 @@ static struct fill_chain *fill_cfg = NULL;
402
403
void add_fill_function(void *data, int (*fill)(void *))
404
{
405
- struct fill_chain *new = malloc(sizeof(*new));
405
+ struct fill_chain *new = xmalloc(sizeof(*new));
406
struct fill_chain **linkp = &fill_cfg;
407
new->data = data;
408
new->fill = fill;
remote.c
+2
-2
@@ -69,7 +69,7 @@ static const char *alias_url(const char *url)
69
if (!longest)
70
return url;
71
72
- ret = malloc(rewrite[longest_i]->baselen +
72
+ ret = xmalloc(rewrite[longest_i]->baselen +
73
(strlen(url) - longest->len) + 1);
74
strcpy(ret, rewrite[longest_i]->base);
75
strcpy(ret + rewrite[longest_i]->baselen, url + longest->len);
@@ -152,7 +152,7 @@ static struct branch *make_branch(const char *name, int len)
152
ret->name = xstrndup(name, len);
153
else
154
ret->name = xstrdup(name);
155
- refname = malloc(strlen(name) + strlen("refs/heads/") + 1);
155
+ refname = xmalloc(strlen(name) + strlen("refs/heads/") + 1);
156
strcpy(refname, "refs/heads/");
157
strcpy(refname + strlen("refs/heads/"), ret->name);
158
ret->refname = refname;