{"thread":{"id":"43468","subject":"Re: [PATCH 3/5] get_shallow_commits: Avoid memory leak if a commit has been reached already.","startedAt":"2006-11-24T14:58:50Z","lastAt":"2006-11-25T23:36:08Z","messageCount":5,"participants":["Johannes Schindelin","Junio C Hamano","Alexandre Julliard","Anand Kumria"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"296952","messageId":"87slg8uc0l.fsf@wine.dyndns.org","threadId":"43468","inReplyTo":null,"subject":"[PATCH 3/5] get_shallow_commits: Avoid memory leak if a commit has been reached already.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2006-11-24T14:58:50Z","receivedAt":"2006-11-24T14:58:50Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"Signed-off-by: Alexandre Julliard <julliard@winehq.org>\n---\n shallow.c |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/shallow.c b/shallow.c\nindex 2db1dc4..3d53d17 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -60,7 +60,9 @@ struct commit_list *get_shallow_commits(\n \t\t\t\t\tcommit = NULL;\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n-\t\t\t\tcommit->util = xcalloc(1, sizeof(int));\n+\t\t\t\tif (!commit->util)\n+\t\t\t\t\tcommit->util = xmalloc(sizeof(int));\n+\t\t\t\t*(int *)commit->util = 0;\n \t\t\t\tcur_depth = 0;\n \t\t\t} else {\n \t\t\t\tcommit = (struct commit *)\n-- \n1.4.4.1.ga335e\n\n-- \nAlexandre Julliard\n"},{"id":"298470","messageId":"ek9u4f$vmk$1@sea.gmane.org","threadId":"43468","inReplyTo":"87slg8uc0l.fsf@wine.dyndns.org","subject":"Re: [PATCH 3/5] get_shallow_commits: Avoid memory leak if a commit has been reached already.","fromName":"Anand Kumria","fromEmail":"wildfire@progsoc.org","sentAt":"2006-11-25T17:22:25Z","receivedAt":"2006-11-25T17:22:25Z","isPatch":true,"sender":{"key":"wildfire@progsoc.org","avatar":null},"body":"On Fri, 24 Nov 2006 15:58:50 +0100, Alexandre Julliard wrote:\n\n> Signed-off-by: Alexandre Julliard <julliard@winehq.org>\n> ---\n>  shallow.c |    4 +++-\n>  1 files changed, 3 insertions(+), 1 deletions(-)\n> \n> diff --git a/shallow.c b/shallow.c\n> index 2db1dc4..3d53d17 100644\n> --- a/shallow.c\n> +++ b/shallow.c\n> @@ -60,7 +60,9 @@ struct commit_list *get_shallow_commits(\n>  \t\t\t\t\tcommit = NULL;\n>  \t\t\t\t\tcontinue;\n>  \t\t\t\t}\n> -\t\t\t\tcommit->util = xcalloc(1, sizeof(int));\n> +\t\t\t\tif (!commit->util)\n> +\t\t\t\t\tcommit->util = xmalloc(sizeof(int));\n> +\t\t\t\t*(int *)commit->util = 0;\n>  \t\t\t\tcur_depth = 0;\n\nHi,\n\nAny reason you didn't do:\n\nif (!commit->util)\n\tcommit->util = xcalloc(1, sizeof(int));\n\nThat would seem to be the same.\n\nRegards,\nAnand\n"},{"id":"296944","messageId":"Pine.LNX.4.63.0611251947310.30004@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43468","inReplyTo":"ek9u4f$vmk$1@sea.gmane.org","subject":"Re: [PATCH 3/5] get_shallow_commits: Avoid memory leak if a commit has been reached already.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-11-25T18:49:32Z","receivedAt":"2006-11-25T18:49:32Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 25 Nov 2006, Anand Kumria wrote:\n\n> Any reason you didn't do:\n> \n> if (!commit->util)\n> \tcommit->util = xcalloc(1, sizeof(int));\n\nxmalloc() does not initialize the memory. Therefore, it is usually \npreferred if you initialize the memory yourself. In this case, the memory \nis initialized to 0, even if it is not allocated.\n\nIt may be a minor performance issue, but it is a good habit to use xcalloc \nonly if it is needed.\n\nCiao,\nDscho\n"},{"id":"296951","messageId":"7v1wnr2twq.fsf@assigned-by-dhcp.cox.net","threadId":"43468","inReplyTo":"Pine.LNX.4.63.0611251947310.30004@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 3/5] get_shallow_commits: Avoid memory leak if a commit has been reached already.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-25T19:44:21Z","receivedAt":"2006-11-25T19:44:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Sat, 25 Nov 2006, Anand Kumria wrote:\n>\n>> Any reason you didn't do:\n>> \n>> if (!commit->util)\n>> \tcommit->util = xcalloc(1, sizeof(int));\n>\n> xmalloc() does not initialize the memory. Therefore, it is usually \n> preferred if you initialize the memory yourself. In this case, the memory \n> is initialized to 0, even if it is not allocated.\n>\n> It may be a minor performance issue, but it is a good habit to use xcalloc \n> only if it is needed.\n\nI think you could pretend the commit->util field to be of some\nkind of int and avoid the allocation altogether ;-).\n"},{"id":"294956","messageId":"Pine.LNX.4.63.0611260033410.30004@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43468","inReplyTo":"7v1wnr2twq.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 3/5] get_shallow_commits: Avoid memory leak if a commit has been reached already.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-11-25T23:36:08Z","receivedAt":"2006-11-25T23:36:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 25 Nov 2006, Junio C Hamano wrote:\n\n> I think you could pretend the commit->util field to be of some kind of \n> int and avoid the allocation altogether ;-).\n\nI actually thought about that, and found it too dangerous. But of course, \nsince we need at least a 32-bit architecture, chances are very high that a \npointer is castable to an int.\n\nCiao,\nDscho\n"}]}