Hello,
Recently I'm getting lot's of "invalid read/invalid write" valgrind errors
which point out at memory allocated for the stack. However the code doesn't
crush and finish running successfully.
I'm trying to understand where the error comes from - and will be grateful
fo any help wih this issue.
Here's what I can see using vgdb:

(gdb) monitor v.info last_error
==10259== Invalid write of size 4
==10259==    at 0x28686C: vsnprintf (in /lib/libc-2.12.so)
==10259==  Address 0x4b43040 is 45,120 bytes inside a block of size 65,536
alloc'd
==10259==    at 0x4005DB9: memalign (vg_replace_malloc.c:727)
==10259==    by 0x4005E68: posix_memalign (vg_replace_malloc.c:876)


-The memory for the stack is allocated using memalign and then the upper and
lower parts of it are protected using mprotect, so the stack looks like
this: 16k protected with mprotect, 32K valid for usage, another 16K
protected. The problem happens only in the valid area.

-The problem always seems to happen in the end of the first page of the
valid memory. For example, the stack above starts with the address 0x4b44000
and goes down, the first inaccessible address is 0x4b4304b.

-The address pointed out as inaccessible is above the stack pointer:
(gdb) info registers
eax            0x100    256
ecx            0x0      0
edx            0x0      0
ebx            0x3acff4 3854324
esp            0x4b42f44        0x4b42f44
ebp            0x4b4304c        0x4b4304c
esi            0x4b43b70        78920560
edi            0x4b431d4        78918100
eip            0x28686c 0x28686c <vsnprintf+12>


-Even though addressibility is not supposed to be affected by mprotect, when
I comment out the calls to mprotect the poblem doen't happen any more.

-There's no specific line in the code that is causing the problem. It seems
that he problem always happens in the end of the first page of the stack. I
tried checkig the memory at the point of allocation - and the pointed out
address is valid. It also seems valid when the thread starts running and
becoms invalid only when the stack reaches near 4K.

Considering the fact there's no crash in the program and it runs normally
and correctly in spite of those errors, I don't understand what is the
reason of valgrind componains.

Any help with the cause of the problem or with further evaluation will be
highly appreciated, as after spending a few days on this I'm run out of
ideas.

Thank you,
Masha.








--
View this message in context: 
http://valgrind.10908.n7.nabble.com/Valgrind-shows-Invalid-write-os-size-4-for-memory-allocated-for-the-stack-tp45597.html
Sent from the Valgrind - Users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to