{"thread":{"id":"15455","subject":"[PATCH] Rename dynamic memory allocation functions to their \"x\" version","startedAt":"2008-09-09T18:57:10Z","lastAt":"2008-09-10T06:02:04Z","messageCount":3,"participants":["Dotan Barak","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"90245","messageId":"200809092157.10185.dotanba@gmail.com","threadId":"15455","inReplyTo":null,"subject":"[PATCH] Rename dynamic memory allocation functions to their \"x\" version","fromName":"Dotan Barak","fromEmail":"dotanba@gmail.com","sentAt":"2008-09-09T18:57:10Z","receivedAt":"2008-09-09T18:57:10Z","isPatch":true,"sender":{"key":"dotanba@gmail.com","avatar":null},"body":"In places that the standard malloc/strdup is used without checking\nif the allocation was successful, I replaced it to xmalloc/xstrdup\nwhich check the memory allocation result.\n\nSigned-off-by: Dotan Barak <dotanba@gmail.com>\n\n---\n\ndiff --git a/builtin-http-fetch.c b/builtin-http-fetch.c\nindex 3a06248..ea2b689 100644\n--- a/builtin-http-fetch.c\n+++ b/builtin-http-fetch.c\n@@ -53,7 +53,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)\n \t}\n \turl = argv[arg];\n \tif (url && url[strlen(url)-1] != '/') {\n-\t\trewritten_url = malloc(strlen(url)+2);\n+\t\trewritten_url = xmalloc(strlen(url)+2);\n \t\tstrcpy(rewritten_url, url);\n \t\tstrcat(rewritten_url, \"/\");\n \t\turl = rewritten_url;\ndiff --git a/git.c b/git.c\nindex adf7352..905acc2 100644\n--- a/git.c\n+++ b/git.c\n@@ -364,7 +364,7 @@ static void handle_internal_command(int argc, const char **argv)\n \tif (sizeof(ext) > 1) {\n \t\ti = strlen(argv[0]) - strlen(ext);\n \t\tif (i > 0 && !strcmp(argv[0] + i, ext)) {\n-\t\t\tchar *argv0 = strdup(argv[0]);\n+\t\t\tchar *argv0 = xstrdup(argv[0]);\n \t\t\targv[0] = cmd = argv0;\n \t\t\targv0[i] = '\\0';\n \t\t}\ndiff --git a/http-push.c b/http-push.c\nindex 6805288..c9dd9a1 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -2237,7 +2237,7 @@ int main(int argc, char **argv)\n \tno_pragma_header = curl_slist_append(no_pragma_header, \"Pragma:\");\n \n \tif (remote->url && remote->url[strlen(remote->url)-1] != '/') {\n-\t\trewritten_url = malloc(strlen(remote->url)+2);\n+\t\trewritten_url = xmalloc(strlen(remote->url)+2);\n \t\tstrcpy(rewritten_url, remote->url);\n \t\tstrcat(rewritten_url, \"/\");\n \t\tremote->url = rewritten_url;\ndiff --git a/http.c b/http.c\nindex 1108ab4..0788936 100644\n--- a/http.c\n+++ b/http.c\n@@ -402,7 +402,7 @@ static struct fill_chain *fill_cfg = NULL;\n \n void add_fill_function(void *data, int (*fill)(void *))\n {\n-\tstruct fill_chain *new = malloc(sizeof(*new));\n+\tstruct fill_chain *new = xmalloc(sizeof(*new));\n \tstruct fill_chain **linkp = &fill_cfg;\n \tnew->data = data;\n \tnew->fill = fill;\ndiff --git a/remote.c b/remote.c\nindex 3ef09a4..3f3c789 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -69,7 +69,7 @@ static const char *alias_url(const char *url)\n \tif (!longest)\n \t\treturn url;\n \n-\tret = malloc(rewrite[longest_i]->baselen +\n+\tret = xmalloc(rewrite[longest_i]->baselen +\n \t\t     (strlen(url) - longest->len) + 1);\n \tstrcpy(ret, rewrite[longest_i]->base);\n \tstrcpy(ret + rewrite[longest_i]->baselen, url + longest->len);\n@@ -152,7 +152,7 @@ static struct branch *make_branch(const char *name, int len)\n \t\tret->name = xstrndup(name, len);\n \telse\n \t\tret->name = xstrdup(name);\n-\trefname = malloc(strlen(name) + strlen(\"refs/heads/\") + 1);\n+\trefname = xmalloc(strlen(name) + strlen(\"refs/heads/\") + 1);\n \tstrcpy(refname, \"refs/heads/\");\n \tstrcpy(refname + strlen(\"refs/heads/\"), ret->name);\n \tret->refname = refname;\n"},{"id":"90309","messageId":"7vprnczlkx.fsf@gitster.siamese.dyndns.org","threadId":"15455","inReplyTo":"200809092157.10185.dotanba@gmail.com","subject":"Re: [PATCH] Rename dynamic memory allocation functions to their \"x\" version","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-09-10T04:11:42Z","receivedAt":"2008-09-10T04:11:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dotan Barak <dotanba@gmail.com> writes:\n\n> In places that the standard malloc/strdup is used without checking\n> if the allocation was successful, I replaced it to xmalloc/xstrdup\n> which check the memory allocation result.\n>\n> Signed-off-by: Dotan Barak <dotanba@gmail.com>\n\nLooks good.  Will apply, but I'd retitle it (it is not \"rename\").\n\nThanks.\n"},{"id":"90316","messageId":"2f3bf9a60809092302u1b8616e6pee3c54003896671c@mail.gmail.com","threadId":"15455","inReplyTo":"7vprnczlkx.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Rename dynamic memory allocation functions to their \"x\" version","fromName":"Dotan Barak","fromEmail":"dotanba@gmail.com","sentAt":"2008-09-10T06:02:04Z","receivedAt":"2008-09-10T06:02:04Z","isPatch":true,"sender":{"key":"dotanba@gmail.com","avatar":null},"body":"On Wed, Sep 10, 2008 at 7:11 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Dotan Barak <dotanba@gmail.com> writes:\n>\n>> In places that the standard malloc/strdup is used without checking\n>> if the allocation was successful, I replaced it to xmalloc/xstrdup\n>> which check the memory allocation result.\n>>\n>> Signed-off-by: Dotan Barak <dotanba@gmail.com>\n>\n> Looks good.  Will apply, but I'd retitle it (it is not \"rename\").\n>\nYes, you are right, i guess \"replace\" is better ...\n\nNext time..\n;)\n\nDotan\n\n> Thanks.\n>\n>\n"}]}