Replace uses of strdup with xstrdup.

Like xmalloc and xrealloc xstrdup dies with a useful message if
the native strdup() implementation returns NULL rather than a
valid pointer.

I just tried to use xstrdup in new code and found it to be missing.
However I expected it to be present as xmalloc and xrealloc are
already commonly used throughout the code.

[jc: removed the part that deals with last_XXX, which I am
 finding more and more dubious these days.]

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Shawn Pearce
2006-09-02 00:16:31 -04:00
committed by Junio C Hamano
parent ad1ed5ee89
commit 9befac470b
34 changed files with 84 additions and 76 deletions

View File

@ -69,7 +69,7 @@ struct ref **get_remote_heads(int in, struct ref **list,
if (len != name_len + 41) {
if (server_capabilities)
free(server_capabilities);
server_capabilities = strdup(name + name_len + 1);
server_capabilities = xstrdup(name + name_len + 1);
}
if (!check_ref(name, name_len, flags))
@ -661,7 +661,7 @@ int git_connect(int fd[2], char *url, const char *prog)
if (path[1] == '~')
path++;
else {
path = strdup(ptr);
path = xstrdup(ptr);
free_path = 1;
}
@ -672,7 +672,7 @@ int git_connect(int fd[2], char *url, const char *prog)
/* These underlying connection commands die() if they
* cannot connect.
*/
char *target_host = strdup(host);
char *target_host = xstrdup(host);
if (git_use_proxy(host))
git_proxy_connect(fd, host);
else