{"thread":{"id":"35984","subject":"[PATCH] Problem in bulk-checkin.c:finish_bulk_checkin() Unable to fix","startedAt":"2014-02-28T00:04:09Z","lastAt":"2014-02-28T05:10:55Z","messageCount":2,"participants":["Faiz Kothari","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"235529","messageId":"1393545849-26775-1-git-send-email-faiz.off93@gmail.com","threadId":"35984","inReplyTo":null,"subject":"[PATCH] Problem in bulk-checkin.c:finish_bulk_checkin() Unable to fix","fromName":"Faiz Kothari","fromEmail":"faiz.off93@gmail.com","sentAt":"2014-02-28T00:04:09Z","receivedAt":"2014-02-28T00:04:09Z","isPatch":true,"sender":{"key":"faiz.off93@gmail.com","avatar":null},"body":"Signed-off-by: Faiz Kothari <faiz.off93@gmail.com>\n---\nCompiles without errors.\nFails in test t/t1050-large.sh ,fails 12/15 tests. Dumps memory map and backtrace.\nSomewhere its not able to free(): invalid pointer.\nPlease somone pointout where I am doing it wrong.\nHelp is really appreciated.\nThanks.\n\n bulk-checkin.c |    8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 118c625..c76cd6b 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -23,7 +23,7 @@ static struct bulk_checkin_state {\n static void finish_bulk_checkin(struct bulk_checkin_state *state)\n {\n \tunsigned char sha1[20];\n-\tchar packname[PATH_MAX];\n+\tstruct strbuf packname = STRBUF_INIT;\n \tint i;\n \n \tif (!state->f)\n@@ -42,9 +42,8 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n \t\t\t\t\t state->offset);\n \t\tclose(fd);\n \t}\n-\n-\tsprintf(packname, \"%s/pack/pack-\", get_object_directory());\n-\tfinish_tmp_packfile(packname, state->pack_tmp_name,\n+\tstrbuf_addf(&packname, \"%s/pack/pack-\", get_object_directory());\n+\tfinish_tmp_packfile(packname.buf, state->pack_tmp_name,\n \t\t\t    state->written, state->nr_written,\n \t\t\t    &state->pack_idx_opts, sha1);\n \tfor (i = 0; i < state->nr_written; i++)\n@@ -53,6 +52,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n clear_exit:\n \tfree(state->written);\n \tmemset(state, 0, sizeof(*state));\n+\tstrbuf_release(&packname);\n \n \t/* Make objects we just wrote available to ourselves */\n \treprepare_packed_git();\n-- \n1.7.9.5\n"},{"id":"235536","messageId":"CAPig+cTMLEw0hkd2fvixyXbszMGrSd2xCa5qm6=cNfcE4fv9yA@mail.gmail.com","threadId":"35984","inReplyTo":"1393545849-26775-1-git-send-email-faiz.off93@gmail.com","subject":"Re: [PATCH] Problem in bulk-checkin.c:finish_bulk_checkin() Unable to fix","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-02-28T05:10:55Z","receivedAt":"2014-02-28T05:10:55Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Feb 27, 2014 at 7:04 PM, Faiz Kothari <faiz.off93@gmail.com> wrote:\n> Signed-off-by: Faiz Kothari <faiz.off93@gmail.com>\n> ---\n> Compiles without errors.\n> Fails in test t/t1050-large.sh ,fails 12/15 tests. Dumps memory map and backtrace.\n> Somewhere its not able to free(): invalid pointer.\n> Please somone pointout where I am doing it wrong.\n> Help is really appreciated.\n> Thanks.\n\nHint: Pay close attention to the second sentence of the microproject\nyou've undertaken:\n\n    Rewrite bulk-checkin.c:finish_bulk_checkin() to use a strbuf for\n    handling packname, and explain why this is useful. Also check if\n    the first argument of pack-write.c:finish_tmp_packfile() can be\n    made const.\n\nIt's the clue to understanding the crash.\n\n>  bulk-checkin.c |    8 ++++----\n>  1 file changed, 4 insertions(+), 4 deletions(-)\n>\n> diff --git a/bulk-checkin.c b/bulk-checkin.c\n> index 118c625..c76cd6b 100644\n> --- a/bulk-checkin.c\n> +++ b/bulk-checkin.c\n> @@ -23,7 +23,7 @@ static struct bulk_checkin_state {\n>  static void finish_bulk_checkin(struct bulk_checkin_state *state)\n>  {\n>         unsigned char sha1[20];\n> -       char packname[PATH_MAX];\n> +       struct strbuf packname = STRBUF_INIT;\n>         int i;\n>\n>         if (!state->f)\n> @@ -42,9 +42,8 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n>                                          state->offset);\n>                 close(fd);\n>         }\n> -\n> -       sprintf(packname, \"%s/pack/pack-\", get_object_directory());\n> -       finish_tmp_packfile(packname, state->pack_tmp_name,\n> +       strbuf_addf(&packname, \"%s/pack/pack-\", get_object_directory());\n> +       finish_tmp_packfile(packname.buf, state->pack_tmp_name,\n>                             state->written, state->nr_written,\n>                             &state->pack_idx_opts, sha1);\n>         for (i = 0; i < state->nr_written; i++)\n> @@ -53,6 +52,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n>  clear_exit:\n>         free(state->written);\n>         memset(state, 0, sizeof(*state));\n> +       strbuf_release(&packname);\n>\n>         /* Make objects we just wrote available to ourselves */\n>         reprepare_packed_git();\n> --\n> 1.7.9.5\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"}]}