{"thread":{"id":"41714","subject":"[PATCH] builtin/apply: free patch when parse_chunk() fails","startedAt":"2016-03-16T19:35:11Z","lastAt":"2016-04-01T17:23:26Z","messageCount":5,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"280950","messageId":"1458156911-26649-1-git-send-email-chriscool@tuxfamily.org","threadId":"41714","inReplyTo":null,"subject":"[PATCH] builtin/apply: free patch when parse_chunk() fails","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-03-16T19:35:11Z","receivedAt":"2016-03-16T19:35:11Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"When parse_chunk() fails it can return -1, for example\nwhen find_header() doesn't find a patch header.\n\nIn this case it's better in apply_patch() to free the\n\"struct patch\" that we just allocated instead of\nleaking it.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin/apply.c | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 42c610e..bf78282 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -4373,8 +4373,10 @@ static int apply_patch(int fd, const char *filename, int options)\n \t\tpatch->inaccurate_eof = !!(options & INACCURATE_EOF);\n \t\tpatch->recount =  !!(options & RECOUNT);\n \t\tnr = parse_chunk(buf.buf + offset, buf.len - offset, patch);\n-\t\tif (nr < 0)\n+\t\tif (nr < 0) {\n+\t\t\tfree_patch(patch);\n \t\t\tbreak;\n+\t\t}\n \t\tif (apply_in_reverse)\n \t\t\treverse_patches(patch);\n \t\tif (use_patch(patch)) {\n-- \n2.8.0.rc2.54.g810e8ee\n"},{"id":"282404","messageId":"CAP8UFD2uT8dF+LMEGVdM6QZztqr_FbX=UQ01U0ttODFUk4AxbA@mail.gmail.com","threadId":"41714","inReplyTo":"1458156911-26649-1-git-send-email-chriscool@tuxfamily.org","subject":"Re: [PATCH] builtin/apply: free patch when parse_chunk() fails","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-03-31T22:29:18Z","receivedAt":"2016-03-31T22:29:18Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wed, Mar 16, 2016 at 3:35 PM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> When parse_chunk() fails it can return -1, for example\n> when find_header() doesn't find a patch header.\n>\n> In this case it's better in apply_patch() to free the\n> \"struct patch\" that we just allocated instead of\n> leaking it.\n\nMaybe this patch has fallen through the cracks too.\n"},{"id":"282408","messageId":"xmqq37r6l0il.fsf@gitster.mtv.corp.google.com","threadId":"41714","inReplyTo":"CAP8UFD2uT8dF+LMEGVdM6QZztqr_FbX=UQ01U0ttODFUk4AxbA@mail.gmail.com","subject":"Re: [PATCH] builtin/apply: free patch when parse_chunk() fails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-31T22:56:34Z","receivedAt":"2016-03-31T22:56:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> On Wed, Mar 16, 2016 at 3:35 PM, Christian Couder\n> <christian.couder@gmail.com> wrote:\n>> When parse_chunk() fails it can return -1, for example\n>> when find_header() doesn't find a patch header.\n>>\n>> In this case it's better in apply_patch() to free the\n>> \"struct patch\" that we just allocated instead of\n>> leaking it.\n>\n> Maybe this patch has fallen through the cracks too.\n\nAnything worthy of discussion that you sent during the feature\nfreeze, please resend them to the list for discussion.\n"},{"id":"282413","messageId":"CAP8UFD18trj9NDuyExB=v8F=sPpUWoL6JdiN9xim-Jo=vkmR9Q@mail.gmail.com","threadId":"41714","inReplyTo":"xmqq37r6l0il.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] builtin/apply: free patch when parse_chunk() fails","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2016-03-31T23:58:41Z","receivedAt":"2016-03-31T23:58:41Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Fri, Apr 1, 2016 at 12:56 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Christian Couder <christian.couder@gmail.com> writes:\n>\n>> On Wed, Mar 16, 2016 at 3:35 PM, Christian Couder\n>> <christian.couder@gmail.com> wrote:\n>>> When parse_chunk() fails it can return -1, for example\n>>> when find_header() doesn't find a patch header.\n>>>\n>>> In this case it's better in apply_patch() to free the\n>>> \"struct patch\" that we just allocated instead of\n>>> leaking it.\n>>\n>> Maybe this patch has fallen through the cracks too.\n>\n> Anything worthy of discussion that you sent during the feature\n> freeze, please resend them to the list for discussion.\n\nIt looks like only the two patches I replied to have not been applied to next.\nI had also sent a three patch long series\n(http://thread.gmane.org/gmane.comp.version-control.git/289559), but\nwe agreed that only two of them could be merged for now and that's\nwhat you did already (fda3e2c and db354b7).\n\nBy the way my guess is that replying to them is ok, but you ask to\n\"resend them\", so I am wondering if you really prefer them to be\nresent rather than just replied to.\n\nThanks!\n"},{"id":"282487","messageId":"xmqqr3epi6pd.fsf@gitster.mtv.corp.google.com","threadId":"41714","inReplyTo":"1458156911-26649-1-git-send-email-chriscool@tuxfamily.org","subject":"Re: [PATCH] builtin/apply: free patch when parse_chunk() fails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-01T17:23:26Z","receivedAt":"2016-04-01T17:23:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> When parse_chunk() fails it can return -1, for example\n> when find_header() doesn't find a patch header.\n>\n> In this case it's better in apply_patch() to free the\n> \"struct patch\" that we just allocated instead of\n> leaking it.\n>\n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  builtin/apply.c | 4 +++-\n\nOK.  Will queue.  Thanks.\n\n>  1 file changed, 3 insertions(+), 1 deletion(-)\n>\n> diff --git a/builtin/apply.c b/builtin/apply.c\n> index 42c610e..bf78282 100644\n> --- a/builtin/apply.c\n> +++ b/builtin/apply.c\n> @@ -4373,8 +4373,10 @@ static int apply_patch(int fd, const char *filename, int options)\n>  \t\tpatch->inaccurate_eof = !!(options & INACCURATE_EOF);\n>  \t\tpatch->recount =  !!(options & RECOUNT);\n>  \t\tnr = parse_chunk(buf.buf + offset, buf.len - offset, patch);\n> -\t\tif (nr < 0)\n> +\t\tif (nr < 0) {\n> +\t\t\tfree_patch(patch);\n>  \t\t\tbreak;\n> +\t\t}\n>  \t\tif (apply_in_reverse)\n>  \t\t\treverse_patches(patch);\n>  \t\tif (use_patch(patch)) {\n"}]}