Re: [PATCH v2] Omit User-Agent: header by default
[notmuch-archives.git] / 81 / 2b9d9c9c79037ea3a3c72989b082391ee99361
1 Return-Path: <bgamari.foss@gmail.com>\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 73131429E25\r
6         for <notmuch@notmuchmail.org>; Tue, 16 Aug 2011 09:32:21 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 BH3T-Z4Nrr2i for <notmuch@notmuchmail.org>;\r
17         Tue, 16 Aug 2011 09:32:20 -0700 (PDT)\r
18 Received: from mail-vx0-f181.google.com (mail-vx0-f181.google.com\r
19         [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 3C34A431FB6\r
22         for <notmuch@notmuchmail.org>; Tue, 16 Aug 2011 09:32:20 -0700 (PDT)\r
23 Received: by vxi39 with SMTP id 39so75274vxi.26\r
24         for <notmuch@notmuchmail.org>; Tue, 16 Aug 2011 09:32:17 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=from:to:subject:user-agent:date:message-id:mime-version\r
27         :content-type; bh=C4MPFfpGTWUoskI2wvxL8fBpYUzDhS7weo9F9fPGeQU=;\r
28         b=vXYloKa+WSYjVLtVZ+wU0tSbyoRmGRQt/e4M7BIdzOOMq7kNIaHD+lp6crNQVIEi+X\r
29         uqptNlkIQoKTZLicXUpS2MkiyS2L+zUhj+wAyUA5Wl9Q0h9NM7XpClS0yQgyHr3IV3Gc\r
30         kzI0/+JzIlqXXdEbPsHlDpFRDMrtn1ZvUrJnw=\r
31 Received: by 10.52.75.137 with SMTP id c9mr4851079vdw.310.1313512337180;\r
32         Tue, 16 Aug 2011 09:32:17 -0700 (PDT)\r
33 Received: from localhost (gamari.physics.umass.edu [128.119.56.223])\r
34         by mx.google.com with ESMTPS id ca9sm232121vdc.39.2011.08.16.09.32.15\r
35         (version=TLSv1/SSLv3 cipher=OTHER);\r
36         Tue, 16 Aug 2011 09:32:15 -0700 (PDT)\r
37 From: Ben Gamari <bgamari.foss@gmail.com>\r
38 To: Bart Massey <bart@cs.pdx.edu>, haskell-cafe@haskell.org,\r
39         notmuch@notmuchmail.org\r
40 Subject: Memory management issue in notmuch-haskell bindings\r
41 User-Agent: Notmuch/0.6.1-76-g1635f57 (http://notmuchmail.org) Emacs/23.2.1\r
42         (x86_64-pc-linux-gnu)\r
43 Date: Tue, 16 Aug 2011 12:32:13 -0400\r
44 Message-ID: <8739h1pbaq.fsf@gmail.com>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Tue, 16 Aug 2011 16:32:21 -0000\r
60 \r
61 It seems that the notmuch-haskell bindings (version 0.2.2 built against\r
62 notmuch from git master; passes notmuch-test) aren't dealing with memory\r
63 management properly. In particular, the attached test code[1] causes\r
64 talloc to abort.  Unfortunately, while the issue is consistently\r
65 reproducible, it only occurs with some queries (see source[1]). I have\r
66 been unable to establish the exact criterion for failure.\r
67 \r
68 It seems that the crash is caused by an invalid access to a freed Query\r
69 object while freeing a Messages object (see Valgrind trace[3]). I've\r
70 taken a brief look at the bindings themselves but, being only minimally\r
71 familiar with the FFI, there's nothing obviously wrong (the finalizers\r
72 passed to newForeignPtr look sane). I was under the impression that\r
73 talloc was reference counted, so the Query object shouldn't have been\r
74 freed unless if there was still a Messages object holding a\r
75 reference. Any idea what might have gone wrong here?  Thanks!\r
76 \r
77 Cheers,\r
78 \r
79 - Ben\r
80 \r
81 \r
82 \r
83 [1] Test case,\r
84 \r
85 import Data.List\r
86 import Control.Monad\r
87 import System.Environment\r
88 import Foreign.Notmuch\r
89 \r
90 dbpath = "/home/ben/.mail"\r
91 \r
92 getAddresses :: Database -> String -> IO [String]\r
93 getAddresses db q = do\r
94         query <- queryCreate db q\r
95         msgs <- queryMessages query\r
96         addrs <- mapM (flip messageGetHeader $ "From") msgs\r
97         return addrs\r
98 \r
99 main = do\r
100         db <- databaseOpen dbpath DatabaseModeReadOnly\r
101         --addrs2 <- getAddresses db "tag:haskell" -- This succeeds\r
102         addrs3 <- getAddresses db "to:dietz" -- This fails\r
103 \r
104         --print addrs2\r
105         --print addrs3\r
106 \r
107         databaseClose db\r
108 \r
109 \r
110 \r
111 [2] Crashed session and backtrace,\r
112 \r
113 [1217 ben@ben-laptop ~] $ ghc test.hs -auto-all -rtsopts -prof && gdb ./test \r
114 GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2\r
115 Copyright (C) 2010 Free Software Foundation, Inc.\r
116 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\r
117 This is free software: you are free to change and redistribute it.\r
118 There is NO WARRANTY, to the extent permitted by law.  Type "show copying"\r
119 and "show warranty" for details.\r
120 This GDB was configured as "x86_64-linux-gnu".\r
121 For bug reporting instructions, please see:\r
122 <http://www.gnu.org/software/gdb/bugs/>...\r
123 Reading symbols from /home/ben/test...(no debugging symbols found)...done.\r
124 (gdb) run\r
125 Starting program: /home/ben/test \r
126 [Thread debugging using libthread_db enabled]\r
127 \r
128 Program received signal SIGABRT, Aborted.\r
129 0x00007ffff5979d05 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64\r
130 64      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.\r
131         in ../nptl/sysdeps/unix/sysv/linux/raise.c\r
132 (gdb) bt\r
133 #0  0x00007ffff5979d05 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64\r
134 #1  0x00007ffff597dab6 in abort () at abort.c:92\r
135 #2  0x00007ffff6de038c in talloc_abort (reason=0x7ffff6de56e8 "Bad talloc magic value - access after free") at ../talloc.c:210\r
136 #3  0x00007ffff6de0271 in talloc_abort_access_after_free (ptr=0x769190, location=0x7ffff7bd4e04 "lib/messages.c:142") at ../talloc.c:229\r
137 #4  talloc_chunk_from_ptr (ptr=0x769190, location=0x7ffff7bd4e04 "lib/messages.c:142") at ../talloc.c:250\r
138 #5  _talloc_free (ptr=0x769190, location=0x7ffff7bd4e04 "lib/messages.c:142") at ../talloc.c:1164\r
139 #6  0x00007ffff7bc7e65 in notmuch_messages_destroy (messages=0x769190) at lib/messages.c:142\r
140 #7  0x00000000004de1c9 in scheduleFinalizers ()\r
141 #8  0x00000000004e013d in GarbageCollect ()\r
142 #9  0x00000000004d9e40 in scheduleDoGC.clone.18 ()\r
143 #10 0x00000000004db0e0 in exitScheduler ()\r
144 #11 0x00000000004d9066 in hs_exit_ ()\r
145 #12 0x00000000004d940a in shutdownHaskellAndExit ()\r
146 #13 0x00000000004d8a91 in real_main ()\r
147 #14 0x00000000004d8ade in hs_main ()\r
148 #15 0x00007ffff5964eff in __libc_start_main (main=0x408ed0 <main>, argc=1, ubp_av=0x7fffffffe4f8, init=<value optimized out>, fini=<value optimized out>, \r
149     rtld_fini=<value optimized out>, stack_end=0x7fffffffe4e8) at libc-start.c:226\r
150 #16 0x0000000000407791 in _start ()\r
151 (gdb) \r
152 \r
153 \r
154 [3] Valgrind output,\r
155 \r
156 ==25241== Memcheck, a memory error detector\r
157 ==25241== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.\r
158 ==25241== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info\r
159 ==25241== Command: ./test\r
160 ==25241== \r
161 ==25241== Conditional jump or move depends on uninitialised value(s)\r
162 ==25241==    at 0x52BB510: inflateReset2 (in /lib/x86_64-linux-gnu/libz.so.1.2.3.4)\r
163 ==25241==    by 0x52BB605: inflateInit2_ (in /lib/x86_64-linux-gnu/libz.so.1.2.3.4)\r
164 ==25241==    by 0x5F211BE: ChertTable::lazy_alloc_inflate_zstream() const (chert_table.cc:1672)\r
165 ==25241==    by 0x5F23B06: ChertTable::read_tag(Cursor*, std::string*, bool) const (chert_table.cc:1264)\r
166 ==25241==    by 0x5F260F9: ChertTable::get_exact_entry(std::string const&, std::string&) const (chert_table.cc:1210)\r
167 ==25241==    by 0x5F26DE2: ChertTermList::ChertTermList(Xapian::Internal::RefCntPtr<ChertDatabase const>, unsigned int) (chert_termlist.cc:44)\r
168 ==25241==    by 0x5EFF2E5: ChertDatabase::open_term_list(unsigned int) const (chert_database.cc:891)\r
169 ==25241==    by 0x5E7E7FB: Xapian::Document::termlist_begin() const (omdocument.cc:176)\r
170 ==25241==    by 0x4E41822: _notmuch_message_ensure_metadata(_notmuch_message*) (message.cc:309)\r
171 ==25241==    by 0x4E429DC: _notmuch_message_ensure_filename_list(_notmuch_message*) (message.cc:632)\r
172 ==25241==    by 0x4E42C37: notmuch_message_get_filename (message.cc:698)\r
173 ==25241==    by 0x4E41CA7: _notmuch_message_ensure_message_file(_notmuch_message*) (message.cc:403)\r
174 ==25241== \r
175 ==25241== Invalid read of size 4\r
176 ==25241==    at 0x5C25DED: _talloc_free (talloc.c:242)\r
177 ==25241==    by 0x4E39E64: notmuch_messages_destroy (messages.c:142)\r
178 ==25241==    by 0x4DE1C8: scheduleFinalizers (in /home/ben/test)\r
179 ==25241==    by 0x4E013C: GarbageCollect (in /home/ben/test)\r
180 ==25241==    by 0x4D9E3F: scheduleDoGC.clone.18 (in /home/ben/test)\r
181 ==25241==    by 0x4DB0DF: exitScheduler (in /home/ben/test)\r
182 ==25241==    by 0x4D9065: hs_exit_ (in /home/ben/test)\r
183 ==25241==    by 0x4D9409: shutdownHaskellAndExit (in /home/ben/test)\r
184 ==25241==    by 0x4D8A90: real_main (in /home/ben/test)\r
185 ==25241==    by 0x4D8ADD: hs_main (in /home/ben/test)\r
186 ==25241==    by 0x6F4FEFE: (below main) (libc-start.c:226)\r
187 ==25241==  Address 0x8324e90 is 64 bytes inside a block of size 136 free'd\r
188 ==25241==    at 0x4C282ED: free (vg_replace_malloc.c:366)\r
189 ==25241==    by 0x5C29884: _talloc_free_internal (talloc.c:714)\r
190 ==25241==    by 0x5C25F22: _talloc_free (talloc.c:667)\r
191 ==25241==    by 0x4E452BF: notmuch_query_destroy (query.cc:358)\r
192 ==25241==    by 0x4DE1C8: scheduleFinalizers (in /home/ben/test)\r
193 ==25241==    by 0x4E013C: GarbageCollect (in /home/ben/test)\r
194 ==25241==    by 0x4D9E3F: scheduleDoGC.clone.18 (in /home/ben/test)\r
195 ==25241==    by 0x4DB0DF: exitScheduler (in /home/ben/test)\r
196 ==25241==    by 0x4D9065: hs_exit_ (in /home/ben/test)\r
197 ==25241==    by 0x4D9409: shutdownHaskellAndExit (in /home/ben/test)\r
198 ==25241==    by 0x4D8A90: real_main (in /home/ben/test)\r
199 ==25241==    by 0x4D8ADD: hs_main (in /home/ben/test)\r
200 ==25241== \r
201 ==25241== Invalid read of size 8\r
202 ==25241==    at 0x5C26251: _talloc_free (talloc.c:249)\r
203 ==25241==    by 0x4E39E64: notmuch_messages_destroy (messages.c:142)\r
204 ==25241==    by 0x4DE1C8: scheduleFinalizers (in /home/ben/test)\r
205 ==25241==    by 0x4E013C: GarbageCollect (in /home/ben/test)\r
206 ==25241==    by 0x4D9E3F: scheduleDoGC.clone.18 (in /home/ben/test)\r
207 ==25241==    by 0x4DB0DF: exitScheduler (in /home/ben/test)\r
208 ==25241==    by 0x4D9065: hs_exit_ (in /home/ben/test)\r
209 ==25241==    by 0x4D9409: shutdownHaskellAndExit (in /home/ben/test)\r
210 ==25241==    by 0x4D8A90: real_main (in /home/ben/test)\r
211 ==25241==    by 0x4D8ADD: hs_main (in /home/ben/test)\r
212 ==25241==    by 0x6F4FEFE: (below main) (libc-start.c:226)\r
213 ==25241==  Address 0x8324e80 is 48 bytes inside a block of size 136 free'd\r
214 ==25241==    at 0x4C282ED: free (vg_replace_malloc.c:366)\r
215 ==25241==    by 0x5C29884: _talloc_free_internal (talloc.c:714)\r
216 ==25241==    by 0x5C25F22: _talloc_free (talloc.c:667)\r
217 ==25241==    by 0x4E452BF: notmuch_query_destroy (query.cc:358)\r
218 ==25241==    by 0x4DE1C8: scheduleFinalizers (in /home/ben/test)\r
219 ==25241==    by 0x4E013C: GarbageCollect (in /home/ben/test)\r
220 ==25241==    by 0x4D9E3F: scheduleDoGC.clone.18 (in /home/ben/test)\r
221 ==25241==    by 0x4DB0DF: exitScheduler (in /home/ben/test)\r
222 ==25241==    by 0x4D9065: hs_exit_ (in /home/ben/test)\r
223 ==25241==    by 0x4D9409: shutdownHaskellAndExit (in /home/ben/test)\r
224 ==25241==    by 0x4D8A90: real_main (in /home/ben/test)\r
225 ==25241==    by 0x4D8ADD: hs_main (in /home/ben/test)\r
226 ==25241== \r
227 ==25241== \r
228 ==25241== HEAP SUMMARY:\r
229 ==25241==     in use at exit: 192,328 bytes in 555 blocks\r
230 ==25241==   total heap usage: 19,852 allocs, 19,297 frees, 35,375,726 bytes allocated\r
231 ==25241== \r
232 ==25241== LEAK SUMMARY:\r
233 ==25241==    definitely lost: 0 bytes in 0 blocks\r
234 ==25241==    indirectly lost: 0 bytes in 0 blocks\r
235 ==25241==      possibly lost: 27,799 bytes in 292 blocks\r
236 ==25241==    still reachable: 164,529 bytes in 263 blocks\r
237 ==25241==         suppressed: 0 bytes in 0 blocks\r
238 ==25241== Rerun with --leak-check=full to see details of leaked memory\r
239 ==25241== \r
240 ==25241== For counts of detected and suppressed errors, rerun with: -v\r
241 ==25241== Use --track-origins=yes to see where uninitialised values come from\r
242 ==25241== ERROR SUMMARY: 4 errors from 3 contexts (suppressed: 4 from 4)\r