From: Kris T. <kri...@gm...> - 2014-06-22 10:29:47
|
>From: William Fulton, Sent: 10 June 2014 19:25 > On 08/06/14 12:18, Kris Thielemans wrote: > > Hi > > > > When attempting to debug my matlab enhancements, I ran valgrind on my > swig > > fork https://github.com/KrisThielemans/swig (forked from Joel Andersson's > > fork which happened at 3rd of April 2014). > > > > Valgrind gives me a lot of "invalid reads", always in the same place, > > independent of which target language that I use. Example: > > > > > > ==25156== > > ==25156== Invalid read of size 4 > > ==25156== at 0x41E76B: DohvPrintf (fio.c:323) > > ==25156== by 0x41EB56: DohPrintf (fio.c:435) > > ==25156== by 0x4F423A: expand_macro (cpp.c:958) > > ==25156== by 0x4F5114: Preprocessor_replace (cpp.c:1149) > > ==25156== by 0x4F5417: add_chunk (cpp.c:1278) > > ==25156== by 0x4F2D14: Preprocessor_parse (cpp.c:1356) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x48AC3E: SWIG_main(int, char**, Language*) > (main.cxx:1065) > > ==25156== by 0x406084: main (swigmain.cxx:208) > > ==25156== Address 0x6275a0c is 908 bytes inside a block of size 911 alloc'd > > ==25156== at 0x4C2AB80: malloc (in > > /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > > ==25156== by 0x41EA6D: DohvPrintf (fio.c:316) > > ==25156== by 0x41EB56: DohPrintf (fio.c:435) > > ==25156== by 0x4F423A: expand_macro (cpp.c:958) > > ==25156== by 0x4F5114: Preprocessor_replace (cpp.c:1149) > > ==25156== by 0x4F5417: add_chunk (cpp.c:1278) > > ==25156== by 0x4F2D14: Preprocessor_parse (cpp.c:1356) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x4F32B1: Preprocessor_parse (cpp.c:1880) > > ==25156== by 0x48AC3E: SWIG_main(int, char**, Language*) > (main.cxx:1065) > > ==25156== > > > > > > The relevant lines in fio.c are > > > > L316 stemp = (char *) DohMalloc(maxwidth + 1); > > > > L323 if (Writen(so, stemp, strlen(stemp)) < 0) > > > > All these warnings disappear if I change L316 to > > > > stemp = (char *) DohMalloc(maxwidth + 4); > > > > why that would be, I have no idea. (maybe something to do with pointer-type > > conversions and memory being read be in 32bit words as opposed to 8bit > > bytes?) > > > Well, if you get to the bottom of it, let us know! > > Because the memory is recycled from pools in Swig, Valgrind isn't always > that useful for debugging. What you are seeing might be a side effect of > a real problem which will be more easily tracked down by defining > SWIG_DEBUG_DELETE in base.c and DOH_DEBUG_MEMORY_POOLS in base.c. > Hi William Enabling these 2 doesn't show up any errors in "normal" swig (of course, it found a bug in the MATLAB module, see separate email). Also, I discovered that the valgrind errors disappear when I change the optimisation level of the C compiler down from -O2 to -O1 (or no optimisation). Hmmm, a compiler bug? I'm using gcc (Ubuntu 4.8.2-19ubuntu1). As I can't see anything wrong in the code in the first place (admittedly I didn't look very hard), I'll ignore this therefore. Kris |