sane-project-website/old-archive/2001-05/0084.html

395 wiersze
13 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>sane-devel: [dev] Memory access violations and leaks</TITLE>
<META NAME="Author" CONTENT="Henning Meier-Geinitz (henning@meier-geinitz.de)">
<META NAME="Subject" CONTENT="[dev] Memory access violations and leaks">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>[dev] Memory access violations and leaks</H1>
<!-- received="Sun May 6 12:45:38 2001" -->
<!-- isoreceived="20010506194538" -->
<!-- sent="Sun, 6 May 2001 21:35:08 +0200" -->
<!-- isosent="20010506193508" -->
<!-- name="Henning Meier-Geinitz" -->
<!-- email="henning@meier-geinitz.de" -->
<!-- subject="[dev] Memory access violations and leaks" -->
<!-- id="20010506213508.A7366@vortex.swb.de" -->
<STRONG>From:</STRONG> Henning Meier-Geinitz (<A HREF="mailto:henning@meier-geinitz.de?Subject=Re:%20[dev]%20Memory%20access%20violations%20and%20leaks&In-Reply-To=&lt;20010506213508.A7366@vortex.swb.de&gt;"><EM>henning@meier-geinitz.de</EM></A>)<BR>
<STRONG>Date:</STRONG> Sun May 06 2001 - 12:35:08 PDT
<P>
<!-- next="start" -->
<LI><STRONG>Next message:</STRONG> <A HREF="0085.html">shailendra mehta: "RE: SANE API &amp; file format"</A>
<UL>
<LI><STRONG>Previous message:</STRONG> <A HREF="0083.html">Henning Meier-Geinitz: "Re: Canon backend"</A>
<!-- nextthread="start" -->
<LI><STRONG>Next in thread:</STRONG> <A HREF="0087.html">abel deuring: "Re: [dev] Memory access violations and leaks"</A>
<LI><STRONG>Reply:</STRONG> <A HREF="0087.html">abel deuring: "Re: [dev] Memory access violations and leaks"</A>
<!-- reply="end" -->
<LI><STRONG>Messages sorted by:</STRONG>
<A HREF="date.html#84">[ date ]</A>
<A HREF="index.html#84">[ thread ]</A>
<A HREF="subject.html#84">[ subject ]</A>
<A HREF="author.html#84">[ author ]</A>
</UL>
<HR NOSHADE><P>
<!-- body="start" -->
<P>
Hi,
<BR>
<P>I did some more work to find accesses to memory that wasn't malloced
<BR>
and memory leaks. If you don't have purify or a similar tool but the
<BR>
GNU C library (glibc) you can check for memory problems this way:
<BR>
<P>Set the environment variable MALLOC_TRACE to a path to a a logfile e.g.:
<BR>
&nbsp;&nbsp;export MALLOC_TRACE=/tmp/malloc.log
<BR>
Edit a frontend (e.g. scanimage) and add #include &lt;mcheck.h&gt; at the
<BR>
beginning and mtrace(); immediately at the start of the main function.
<BR>
When scanimage is started a log about each malloc() and free() is
<BR>
written into /tmp/malloc.log. The program mtrace helps to find freed
<BR>
memory that was never malloced and malloced memory that isn't freed:
<BR>
&nbsp;&nbsp;mtrace /usr/local/scanimage /tmp/mtrace.log
<BR>
<P>More information is in info libc.
<BR>
<P>It's easier if scanimage is linked statically to the libs. If you only
<BR>
want to check your backend, link it directly to scanimage (without dll
<BR>
and other backends).
<BR>
<P>The following backends seem to use lines like if (config_line[len - 1] == '\n')
<BR>
to remove \n at the end of a line. This is not necessary because it's
<BR>
done already in sanei_config_read(). It can cause problems when len=0.
<BR>
That's just a fast grep, maybe I missed some or am wrong with some.
<BR>
<P>- artec
<BR>
- bh
<BR>
- epson
<BR>
- m3096g
<BR>
- microtek2
<BR>
- mustek_pp
<BR>
- pie
<BR>
- sp15c
<BR>
- umax
<BR>
<P>There seem to be a memory leak in sanei/sanei_scsi.c line 1271 but I
<BR>
haven't looked into the details.
<BR>
<P>There are some more memory leaks in sanei_wire.c (or maybe in
<BR>
sanei_net.c or net.c) but I couldn't locate the exact problem yet.
<BR>
Probably a missing wire_free() somewhere.
<BR>
<P>There are probably some more leaks especially in the case of memory
<BR>
allocated by str(n)dup that's not freed.
<BR>
<P>In nearly every backend there is a memory leak in sane_get_devices().
<BR>
I don't think it's too grave because the list is only created once and
<BR>
freed before the next creation. But nevertheless this should be fixed.
<BR>
Backends:
<BR>
<P>- abaton
<BR>
- agfafocus
<BR>
- apple
<BR>
- artec
<BR>
- as6e
<BR>
- avision
<BR>
- bh
<BR>
- canon
<BR>
- coolscan
<BR>
- dmc
<BR>
- epson
<BR>
- m3096
<BR>
- microtek
<BR>
- microtek2 ?
<BR>
- nec
<BR>
- pie
<BR>
- plustek
<BR>
- qcam
<BR>
- ricoh
<BR>
- s9036
<BR>
- sharp
<BR>
- sp15c
<BR>
- tamarack
<BR>
- umax
<BR>
- umax_pp
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<BR>
Here is an example log from running scanimage -L:
<BR>
<P>Memory not freed:
<BR>
-----------------
<BR>
&nbsp;&nbsp;&nbsp;Address Size Caller
<BR>
0x08174dc0 0x4 at /usr/src/sane/sane-backends/backend/umax_pp.c:946
<BR>
0x08174dd0 0x4 at /usr/src/sane/sane-backends/backend/umax.c:5394
<BR>
0x08174de0 0x1 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08174df0 0xd at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08174e08 0x8 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08174e18 0x4 at /usr/src/sane/sane-backends/backend/tamarack.c:935
<BR>
0x08174ec0 0x4 at /usr/src/sane/sane-backends/backend/sp15c.c:273
<BR>
0x08174f78 0x4 at /usr/src/sane/sane-backends/backend/plustek.c:863
<BR>
0x08174f88 0x4 at /usr/src/sane/sane-backends/backend/pie.c:2991
<BR>
0x08174f98 0x4 at /usr/src/sane/sane-backends/backend/nec.c:2165
<BR>
0x08174fe0 0x4 at /usr/src/sane/sane-backends/backend/sharp.c:2484
<BR>
0x08174ff0 0x4 at /usr/src/sane/sane-backends/backend/s9036.c:878
<BR>
0x08175000 0x4 at /usr/src/sane/sane-backends/backend/ricoh.c:548
<BR>
0x08175010 0x4 at /usr/src/sane/sane-backends/backend/qcam.c:1444
<BR>
0x08175020 0xd at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08175048 0x1 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x081753c0 0x16c at /usr/src/sane/sane-backends/sanei/sanei_scsi.c:1271
<BR>
0x08175960 0x24 at /usr/src/sane/sane-backends/backend/microtek2.c:5032
<BR>
0x08175988 0x24 at /usr/src/sane/sane-backends/backend/microtek2.c:5032
<BR>
0x081759b0 0x11 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x081759d8 0x4 at /usr/src/sane/sane-backends/backend/microtek.c:2933
<BR>
0x08175aa8 0x4 at /usr/src/sane/sane-backends/backend/m3096g.c:276
<BR>
0x08175ac8 0x4 at /usr/src/sane/sane-backends/backend/epson.c:2085
<BR>
0x08175ad8 0x4 at /usr/src/sane/sane-backends/backend/dmc.c:885
<BR>
0x08175ae8 0x4 at /usr/src/sane/sane-backends/backend/coolscan.c:3284
<BR>
0x08175af8 0x4 at /usr/src/sane/sane-backends/backend/canon-sane.c:74
<BR>
0x08175b08 0xd at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08175b20 0x4 at /usr/src/sane/sane-backends/backend/bh.c:3239
<BR>
0x08175b30 0x14 at /usr/src/sane/sane-backends/backend/as6e.c:841
<BR>
0x08175b48 0xb at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08176f90 0x4 at /usr/src/sane/sane-backends/backend/artec.c:2668
<BR>
0x08176fa0 0x1 at /lib/libc.so.6:(strndup+0x3e)[0x400c6cbe]
<BR>
0x08176fb0 0x4 at /usr/src/sane/sane-backends/backend/avision.c:1469
<BR>
0x08176fc0 0x4 at /usr/src/sane/sane-backends/backend/apple.c:1928
<BR>
0x08176fd0 0x4 at /usr/src/sane/sane-backends/backend/agfafocus.c:1326
<BR>
0x08176fe0 0x4 at /usr/src/sane/sane-backends/backend/abaton.c:913
<BR>
0x08177038 0xb at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x0817b8f0 0x60 at /lib/ld-linux.so.2:(_dl_debug_message+0x841)[0x4000af8d]
<BR>
0x0817df20 0x6 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817df30 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:186
<BR>
0x0817df48 0x6 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817df58 0x7 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817df68 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817df80 0xf at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817df98 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:186
<BR>
0x0817dfb0 0x6 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817dfc0 0x7 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817dfd0 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817dfe8 0xf at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x0817e000 0x44 at /usr/src/sane/sane-backends/backend/net.c:498
<BR>
0x0817e0b8 0x7 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x0817e0c8 0x10 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x0817e0e0 0xf at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x0817e168 0x7 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x0817e178 0x10 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x0817e190 0xf at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x081801c8 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:186
<BR>
0x081801e0 0x7 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x081801f0 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180208 0xf at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180220 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:186
<BR>
0x08180238 0x6 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180248 0x7 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180258 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180270 0xf at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180288 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:186
<BR>
0x081802a0 0x14 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x081802b8 0x7 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x081802c8 0x14 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x081802e0 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x081802f8 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:186
<BR>
0x08180310 0x13 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180328 0x8 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180338 0x9 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x08180348 0x10 at /usr/src/sane/sane-backends/sanei/sanei_wire.c:146
<BR>
0x081803d0 0x7 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x081803e0 0x10 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x081803f8 0xf at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180480 0x7 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180490 0x10 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x081804a8 0xf at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180540 0x7 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180550 0x14 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180568 0x10 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180600 0x8 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180610 0x9 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180620 0x10 at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180938 0xb at /lib/libc.so.6:(__strdup+0x2f)[0x400c6c5f]
<BR>
0x08180948 0xb at /usr/src/sane/sane-backends/backend/dc25.c:1725
<BR>
0x0818a7c0 0x10000 at /usr/src/sane/sane-backends/backend/coolscan.c:2102
<BR>
<P><P>Bye,
<BR>
&nbsp;&nbsp;Henning
<BR>
<P><PRE>
--
Source code, list archive, and docs: <A HREF="http://www.mostang.com/sane/">http://www.mostang.com/sane/</A>
To unsubscribe: echo unsubscribe sane-devel | mail <A HREF="mailto:majordomo@mostang.com?Subject=Re:%20[dev]%20Memory%20access%20violations%20and%20leaks&In-Reply-To=&lt;20010506213508.A7366@vortex.swb.de&gt;">majordomo@mostang.com</A>
</PRE>
<P><!-- body="end" -->
<HR NOSHADE>
<UL>
<!-- next="start" -->
<LI><STRONG>Next message:</STRONG> <A HREF="0085.html">shailendra mehta: "RE: SANE API &amp; file format"</A>
<LI><STRONG>Previous message:</STRONG> <A HREF="0083.html">Henning Meier-Geinitz: "Re: Canon backend"</A>
<!-- nextthread="start" -->
<LI><STRONG>Next in thread:</STRONG> <A HREF="0087.html">abel deuring: "Re: [dev] Memory access violations and leaks"</A>
<LI><STRONG>Reply:</STRONG> <A HREF="0087.html">abel deuring: "Re: [dev] Memory access violations and leaks"</A>
<!-- reply="end" -->
<LI><STRONG>Messages sorted by:</STRONG>
<A HREF="date.html#84">[ date ]</A>
<A HREF="index.html#84">[ thread ]</A>
<A HREF="subject.html#84">[ subject ]</A>
<A HREF="author.html#84">[ author ]</A>
</UL>
<!-- trailer="footer" -->
<HR NOSHADE>
<P>
<SMALL>
<EM>
This archive was generated by <A HREF="http://www.hypermail.org/">hypermail 2b29</A>
: <EM>Sun May 06 2001 - 12:51:57 PDT</EM>
</EM>
</SMALL>
</BODY>
</HTML>