summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 97410b2)
raw | patch | inline | side by side (parent: 97410b2)
author | Brandon Casey <drafnel@gmail.com> | |
Thu, 6 Oct 2011 18:22:22 +0000 (13:22 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 6 Oct 2011 20:54:32 +0000 (13:54 -0700) |
The "x"-prefixed versions of strdup, malloc, etc. will check whether the
allocation was successful and terminate the process otherwise.
A few uses of malloc were left alone since they already implemented a
graceful path of failure or were in a quasi external library like xdiff.
Additionally, the call to malloc in compat/win32/syslog.c was not modified
since the syslog() implemented there is a die handler and a call to the
x-wrappers within a die handler could result in recursion should memory
allocation fail. This will have to be addressed separately.
Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
allocation was successful and terminate the process otherwise.
A few uses of malloc were left alone since they already implemented a
graceful path of failure or were in a quasi external library like xdiff.
Additionally, the call to malloc in compat/win32/syslog.c was not modified
since the syslog() implemented there is a die handler and a call to the
x-wrappers within a die handler could result in recursion should memory
allocation fail. This will have to be addressed separately.
Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
attr.c | patch | blob | history | |
builtin/mv.c | patch | blob | history | |
compat/mingw.c | patch | blob | history | |
compat/qsort.c | patch | blob | history | |
remote.c | patch | blob | history | |
show-index.c | patch | blob | history | |
transport-helper.c | patch | blob | history |
index fe38fcc36bcdbdfba5c06128aa41247125169e37..0793859b71aa9a425005665a118bec1ab54fec37 100644 (file)
--- a/attr.c
+++ b/attr.c
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
elem = read_attr(GITATTRIBUTES_FILE, 1);
- elem->origin = strdup("");
+ elem->origin = xstrdup("");
elem->prev = attr_stack;
attr_stack = elem;
debug_push(elem);
diff --git a/builtin/mv.c b/builtin/mv.c
index 40f33ca4d0e6d0bb1733e0544029c6f588d09b59..e9d191f0562df86d9a19311704cb5fc77e9b8caf 100644 (file)
--- a/builtin/mv.c
+++ b/builtin/mv.c
to_copy--;
if (to_copy != length || base_name) {
char *it = xmemdupz(result[i], to_copy);
- result[i] = base_name ? strdup(basename(it)) : it;
+ result[i] = base_name ? xstrdup(basename(it)) : it;
}
}
return get_pathspec(prefix, result);
diff --git a/compat/mingw.c b/compat/mingw.c
index 6ef0cc4f99becd772a6fed1cfe2484a67b3a9000..8947418ce78faa3619779c12319c0dd99b1557d3 100644 (file)
--- a/compat/mingw.c
+++ b/compat/mingw.c
}
ai->ai_addrlen = sizeof(struct sockaddr_in);
if (hints && (hints->ai_flags & AI_CANONNAME))
- ai->ai_canonname = h ? strdup(h->h_name) : NULL;
+ ai->ai_canonname = h ? xstrdup(h->h_name) : NULL;
else
ai->ai_canonname = NULL;
diff --git a/compat/qsort.c b/compat/qsort.c
index d93dce2cf8fa33bd1fbefe131d2e41a6b954da61..9574d537bd38d3aa72ee040b106456088ee16a07 100644 (file)
--- a/compat/qsort.c
+++ b/compat/qsort.c
msort_with_tmp(b, n, s, cmp, buf);
} else {
/* It's somewhat large, so malloc it. */
- char *tmp = malloc(size);
+ char *tmp = xmalloc(size);
msort_with_tmp(b, n, s, cmp, tmp);
free(tmp);
}
diff --git a/remote.c b/remote.c
index b8ecfa5d9558e3824872ad6778fc344681cc8d5c..7840d2f9b97b8c100012386aad265d422ec802d0 100644 (file)
--- a/remote.c
+++ b/remote.c
refspec->dst, &ret))
return ret;
} else if (!strcmp(refspec->src, name))
- return strdup(refspec->dst);
+ return xstrdup(refspec->dst);
}
return NULL;
}
diff --git a/show-index.c b/show-index.c
index 4c0ac138aff7b5add73e17fc9c3c4e409fd918e2..63f9da53237d4233bede66a28e4bcf27d5b44af1 100644 (file)
--- a/show-index.c
+++ b/show-index.c
unsigned char sha1[20];
uint32_t crc;
uint32_t off;
- } *entries = malloc(nr * sizeof(entries[0]));
+ } *entries = xmalloc(nr * sizeof(entries[0]));
for (i = 0; i < nr; i++)
if (fread(entries[i].sha1, 20, 1, stdin) != 1)
die("unable to read sha1 %u/%u", i, nr);
diff --git a/transport-helper.c b/transport-helper.c
index 4eab844d4abfa29ce53b6245a5821ee7be03641b..07131261fefeab2066636a7f83bce05796329a54 100644 (file)
--- a/transport-helper.c
+++ b/transport-helper.c
ALLOC_GROW(refspecs,
refspec_nr + 1,
refspec_alloc);
- refspecs[refspec_nr++] = strdup(capname + strlen("refspec "));
+ refspecs[refspec_nr++] = xstrdup(capname + strlen("refspec "));
} else if (!strcmp(capname, "connect")) {
data->connect = 1;
} else if (!prefixcmp(capname, "export-marks ")) {
if (data->refspecs)
private = apply_refspecs(data->refspecs, data->refspec_nr, posn->name);
else
- private = strdup(posn->name);
+ private = xstrdup(posn->name);
read_ref(private, posn->old_sha1);
free(private);
}