> Is this actually causing problems for you, or are you just wanting
valgrind to be quieter?

This indicates a serious problem. The program is reading outside the allocated 
block. Under some circumstances, the program may still work as intended, 
because the program happens to be allowed to read that particular memory region 
(and it does not use the bytes originating from outside the block). But in the 
general case it will cause a segmentation fault. I can not reproduce the 
problem with that particular test program (using Gentoo here), but Valgrind is 
an excellent tool for finding such errors. Another tool that will detect this 
is efence. I made a similar testcase:
#include <cstdlib>
int main (int argc, char * * argv) {
        int * const a = static_cast<int *> (calloc (17, 1));
        int const result = a[4];
        free (a);
        return result;
}

% g++ main.cc -o main
% valgrind ./main
Invalid read of size 4
   at 0x80484C2: main (main.cc:4)
 Address 0x4295038 is 16 bytes inside a block of size 17 alloc'd
   at 0x4021EEE: calloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
   by 0x80484B8: main (main.cc:3)

Now add -lefence to the build command and run the program with
"EF_ALIGNMENT=1 ./main". It will show what happens when the memory
immediately after the block does not happen to be accessible to the
program:

ElectricFence: Registering with atexit().
ElectricFence: If this hangs, change the library load order with LD_PRELOAD.
ElectricFence: Registration was successful.
Segmentation fault

-- 
valgrind finds "Invalid read of size 4" in dlopen
https://bugs.launchpad.net/bugs/114032
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to