Re: [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header
[notmuch-archives.git] / 76 / c6d497f571672d52ef91f30ab490796895397d
1 Return-Path: <cworth@cworth.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 4AC1440DACE\r
6         for <notmuch@notmuchmail.org>; Mon,  8 Nov 2010 09:20:05 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.89\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.89 tagged_above=-999 required=5\r
12         tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, T_MIME_NO_TEXT=0.01]\r
13         autolearn=ham\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id crZTeFN5BWxm; Mon,  8 Nov 2010 09:19:55 -0800 (PST)\r
17 Received: from yoom.home.cworth.org (localhost [127.0.0.1])\r
18         by olra.theworths.org (Postfix) with ESMTP id 1355740DAC4;\r
19         Mon,  8 Nov 2010 09:19:53 -0800 (PST)\r
20 Received: by yoom.home.cworth.org (Postfix, from userid 1000)\r
21         id 13AA225412B; Mon,  8 Nov 2010 09:19:50 -0800 (PST)\r
22 From: Carl Worth <cworth@cworth.org>\r
23 To: Michael Forney <mforney@mforney.org>, notmuch@notmuchmail.org\r
24 Subject: Re: [PATCH] lib: Fix memory leaks in notmuch_message_file_get_header\r
25 In-Reply-To: <1288928975-10041-1-git-send-email-mforney@mforney.org>\r
26 References: <1288928975-10041-1-git-send-email-mforney@mforney.org>\r
27 User-Agent: Notmuch/0.4 (http://notmuchmail.org) Emacs/23.2.1\r
28         (i486-pc-linux-gnu)\r
29 Date: Mon, 08 Nov 2010 09:19:49 -0800\r
30 Message-ID: <877hgnohqi.fsf@yoom.home.cworth.org>\r
31 MIME-Version: 1.0\r
32 Content-Type: multipart/signed; boundary="=-=-=";\r
33         micalg=pgp-sha1; protocol="application/pgp-signature"\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Mon, 08 Nov 2010 17:20:05 -0000\r
47 \r
48 --=-=-=\r
49 Content-Transfer-Encoding: quoted-printable\r
50 \r
51 On Thu,  4 Nov 2010 20:49:35 -0700, Michael Forney <mforney@mforney.org> wr=\r
52 ote:\r
53 > When decoded_value, header_sofar, and header are unused, they should\r
54 > be freed.\r
55 \r
56 Thanks for the cleanups here. Just looking over the patch it's clear\r
57 that I let some code into message-file.c without coercing the style into\r
58 what I would really prefer to see, (should use talloc more, should move\r
59 away from overly-abbreviated identifiers such as "hdrsofar", and\r
60 shouldn't have ambiguously named identifiers such as "header_sofar" and\r
61 "hdrsofar").\r
62 \r
63 > +             free(decoded_value);\r
64 > +             free(header_sofar);\r
65 >               g_hash_table_insert (message->headers, header, combined_header);\r
66 >           }\r
67 >       } else {\r
68 >           if (header_sofar =3D=3D NULL) {\r
69 >               /* Only insert if we don't have a value for this header, yet. */\r
70 >               g_hash_table_insert (message->headers, header, decoded_value);\r
71 > +         } else {\r
72 > +             free(header);\r
73 > +             free(decoded_value);\r
74 \r
75 But I didn't push the change yet. The above do look like memory leak\r
76 fixes as described in the commit message.\r
77 \r
78 >       if (match && !is_received)\r
79 > -         return decoded_value;\r
80 > +         return header_sofar =3D=3D NULL ? decoded_value : header_sofar;\r
81 >      }\r
82 \r
83 But this part looks like an independent bug fix that needs its own\r
84 description, (and perhaps a test case?). Could you please split the\r
85 patch into two?\r
86 \r
87 Thanks,\r
88 \r
89 =2DCarl\r
90 \r
91 =2D-=20\r
92 carl.d.worth@intel.com\r
93 \r
94 --=-=-=\r
95 Content-Type: application/pgp-signature\r
96 \r
97 -----BEGIN PGP SIGNATURE-----\r
98 Version: GnuPG v1.4.10 (GNU/Linux)\r
99 \r
100 iD8DBQFM2DE16JDdNq8qSWgRAtAQAJ9nhgK2kH9mZ0ZAhgbrRd+hMwnx7gCghI/z\r
101 ia83IEyQ7E5LCEtSdfD4kyo=\r
102 =MyAu\r
103 -----END PGP SIGNATURE-----\r
104 --=-=-=--\r