Re: [PATCH 1/2] build: add canonicalize_file_name to symbols exported from libnotmuch.so
[notmuch-archives.git] / 94 / 65c2324f6928a6890e0420d94735ef2aea7aec
1 Return-Path: <tomi.ollila@iki.fi>\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 EEBAF431FBC\r
6         for <notmuch@notmuchmail.org>; Mon, 10 Dec 2012 20:51:00 -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: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 9ijrhsgKAGjp for <notmuch@notmuchmail.org>;\r
16         Mon, 10 Dec 2012 20:50:57 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 71D9B431FB6\r
19         for <notmuch@notmuchmail.org>; Mon, 10 Dec 2012 20:50:55 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id CB7A110007E;\r
22         Tue, 11 Dec 2012 06:50:49 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: david@tethera.net, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH] notmuch_message_file_get_header: replace free with g_free\r
26 In-Reply-To: <1355188740-6663-1-git-send-email-david@tethera.net>\r
27 References: <1355188740-6663-1-git-send-email-david@tethera.net>\r
28 User-Agent: Notmuch/0.14+116~g29fcdb5 (http://notmuchmail.org) Emacs/24.2.1\r
29         (x86_64-unknown-linux-gnu)\r
30 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
31         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
32         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
33 Date: Tue, 11 Dec 2012 06:50:49 +0200\r
34 Message-ID: <m2a9tlfaza.fsf@guru.guru-group.fi>\r
35 MIME-Version: 1.0\r
36 Content-Type: text/plain\r
37 Cc: David Bremner <bremner@debian.org>\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Tue, 11 Dec 2012 04:51:01 -0000\r
51 \r
52 On Tue, Dec 11 2012, david@tethera.net wrote:\r
53 \r
54 > From: David Bremner <bremner@debian.org>\r
55 >\r
56 > The pointer returned by g_mime_utils_header_decode_text is from the\r
57 > following line in rfc2047_decode_tokens\r
58 >\r
59 >       return g_string_free (decoded, FALSE);\r
60 >\r
61 > The docs for g_string_free say\r
62 >\r
63 >  Frees the memory allocated for the GString. If free_segment is TRUE\r
64 >  it also frees the character data. If it's FALSE, the caller gains\r
65 >  ownership of the buffer and must free it after use with g_free().\r
66 > ---\r
67 \r
68 There is still some problem left: in the contex one can see the following\r
69 calls:\r
70 \r
71    g_hash_table_insert (message->headers, header, decoded_value);\r
72 \r
73 and then\r
74 \r
75    combined_header = xmalloc(hdrsofar + newhdr + 2);\r
76    strncpy(combined_header,header_sofar,hdrsofar);\r
77    *(combined_header+hdrsofar) = ' ';\r
78    strncpy(combined_header+hdrsofar+1,decoded_value,newhdr+1);\r
79    g_free (decoded_value);\r
80    g_hash_table_insert (message->headers, header, combined_header);\r
81 \r
82 Now, decoded_value should always be freed with g_free() and combined_header\r
83 with free(), note also that the hash table is initialized with:\r
84 \r
85    message->headers = g_hash_table_new_full (strcase_hash,\r
86                                              strcase_equal,\r
87                                              free,\r
88                                              free);\r
89 \r
90 i.e. finally the allocated string is freed with free() (in case\r
91 we're freeing... I did not look so far...).\r
92 \r
93 Maybe all allocations and frees in the values of this header hash table\r
94 should be converted to use g_ -functions ? (or start to use talloc contex\r
95 there)\r
96 \r
97 \r
98 Tomi\r
99 \r
100 \r
101 \r
102 \r
103 \r
104 >  lib/message-file.c |    4 ++--\r
105 >  1 file changed, 2 insertions(+), 2 deletions(-)\r
106 >\r
107 > diff --git a/lib/message-file.c b/lib/message-file.c\r
108 > index 915aba8..976769d 100644\r
109 > --- a/lib/message-file.c\r
110 > +++ b/lib/message-file.c\r
111 > @@ -341,7 +341,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,\r
112 >               strncpy(combined_header,header_sofar,hdrsofar);\r
113 >               *(combined_header+hdrsofar) = ' ';\r
114 >               strncpy(combined_header+hdrsofar+1,decoded_value,newhdr+1);\r
115 > -             free (decoded_value);\r
116 > +             g_free (decoded_value);\r
117 >               g_hash_table_insert (message->headers, header, combined_header);\r
118 >           }\r
119 >       } else {\r
120 > @@ -350,7 +350,7 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,\r
121 >               g_hash_table_insert (message->headers, header, decoded_value);\r
122 >           } else {\r
123 >               free (header);\r
124 > -             free (decoded_value);\r
125 > +             g_free (decoded_value);\r
126 >               decoded_value = header_sofar;\r
127 >           }\r
128 >       }\r
129 > -- \r
130 > 1.7.10.4\r
131 >\r
132 > _______________________________________________\r
133 > notmuch mailing list\r
134 > notmuch@notmuchmail.org\r
135 > http://notmuchmail.org/mailman/listinfo/notmuch\r