Valgrind: Invalid read of size 1

How to read this:

Invalid read of size 1

Your program is trying to read one byte from somewhere that Valgrind doesn’t like.

at 0x401569: main (:395)

Where in the code this happens (clearly strcmp has been inlined)

Address 0x0 is not stack’d malloc’d or (recently) free’d

What the address it was reading – 0x0 is “NULL”. The rest of the statement just says why it’s invalid (it’s not from the stack, it’s not something you’ve got from malloc, and not been freed recently). The “recently” is mentioned because valgrind keeps track of freed memory for a limited number of frees, so it can’t say for sure that it wasn’t freed a million frees back – in this case it wasn’t, but if you see a message like that, it MAY be that it has become invalid because it was freed ages ago. The address would not be zero tho’ (or near zero).

Leave a Comment