davidfstr/rdiscount — pull request #99 by dbussink (2013-05-04 07:46:37+00:00)
Title: Don't read free'd memory when switching locales

According to valgrind, setlocale actually frees the buffer that is
returned when running setlocale() with a NULL argument to retrieve the
current locale.

This means it's needed to duplicate the retrieved locale and free it
after putting it back.

This is how valgrind reports this issue:

==27152== Invalid read of size 1
==27152== at 0x4C2CBC1: __GI_strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27152== by 0x5ED2430: setlocale (setlocale.c:210)
==27152== by 0xECB241B: rb_rdiscount_to_html (rdiscount.c:44)
...

==27152== Address 0x63b7d50 is 0 bytes inside a block of size 6 free'd
==27152== at 0x4C2A82E: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27152== by 0x5ED256A: setlocale (setlocale.c:173)
==27152== by 0xECB23CC: rb_rdiscount_to_html (rdiscount.c:30)
...