{"thread":{"id":"43802","subject":"[PATCH] mailinfo: recycle strbuf in check_header()","startedAt":"2016-08-13T09:05:54Z","lastAt":"2016-08-13T09:05:54Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"298956","messageId":"57AEE2E6.2090508@web.de","threadId":"43802","inReplyTo":null,"subject":"[PATCH] mailinfo: recycle strbuf in check_header()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2016-08-13T09:05:42Z","receivedAt":"2016-08-13T09:05:54Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"handle_message_id() duplicates the contents of the strbuf that is passed\nto it.  Its only caller proceeds to release the strbuf immediately after\nthat.  Reuse it instead and make that change of object ownership more\nobvious by inlining this short function.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n mailinfo.c | 9 ++-------\n 1 file changed, 2 insertions(+), 7 deletions(-)\n\ndiff --git a/mailinfo.c b/mailinfo.c\nindex 9f19ca1..e19abe3 100644\n--- a/mailinfo.c\n+++ b/mailinfo.c\n@@ -179,12 +179,6 @@ static void handle_content_type(struct mailinfo *mi, struct strbuf *line)\n \t}\n }\n \n-static void handle_message_id(struct mailinfo *mi, const struct strbuf *line)\n-{\n-\tif (mi->add_message_id)\n-\t\tmi->message_id = strdup(line->buf);\n-}\n-\n static void handle_content_transfer_encoding(struct mailinfo *mi,\n \t\t\t\t\t     const struct strbuf *line)\n {\n@@ -495,7 +489,8 @@ static int check_header(struct mailinfo *mi,\n \t\tlen = strlen(\"Message-Id: \");\n \t\tstrbuf_add(&sb, line->buf + len, line->len - len);\n \t\tdecode_header(mi, &sb);\n-\t\thandle_message_id(mi, &sb);\n+\t\tif (mi->add_message_id)\n+\t\t\tmi->message_id = strbuf_detach(&sb, NULL);\n \t\tret = 1;\n \t\tgoto check_header_out;\n \t}\n-- \n2.9.3\n\n"}]}