msgpack / msgpack-c

MessagePack implementation for C and C++ / msgpack.org[C/C++]
Other
3.03k stars 883 forks source link

Fix Unpack example from quickstart segfaults #1100 #1103

Open Arenoros opened 9 months ago

Arenoros commented 9 months ago

Found the cause of the segfault.

valgrind output before fix ``` $ g++ main.cpp -I ../../lib/ -O3 -g $ valgrind ./a.out ==1775== Memcheck, a memory error detector ==1775== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==1775== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==1775== Command: ./a.out ==1775== "Log message ... 1" ==1775== Invalid read of size 8 ==1775== at 0x10AAB0: operator() (cpp11_zone.hpp:33) ==1775== by 0x10AAB0: clear (cpp11_zone.hpp:49) ==1775== by 0x10AAB0: ~finalizer_array (cpp11_zone.hpp:43) ==1775== by 0x10AAB0: ~zone (cpp11_zone.hpp:196) ==1775== by 0x10AAB0: operator() (unique_ptr.h:85) ==1775== by 0x10AAB0: reset (unique_ptr.h:182) ==1775== by 0x10AAB0: reset (unique_ptr.h:456) ==1775== by 0x10AAB0: next (unpack.hpp:96) ==1775== by 0x10AAB0: next (unpack.hpp:92) ==1775== by 0x10AAB0: next (unpack.hpp:109) ==1775== by 0x10AAB0: main (main.cpp:155) ==1775== Address 0x4dea108 is 8 bytes inside a block of size 24 free'd ==1775== at 0x484BB6F: operator delete(void*, unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1775== by 0x10AA5F: clear (cpp11_zone.hpp:52) ==1775== by 0x10AA5F: ~finalizer_array (cpp11_zone.hpp:43) ==1775== by 0x10AA5F: ~zone (cpp11_zone.hpp:190) ==1775== by 0x10AA5F: operator() (unique_ptr.h:85) ==1775== by 0x10AA5F: reset (unique_ptr.h:182) ==1775== by 0x10AA5F: reset (unique_ptr.h:456) ==1775== by 0x10AA5F: next (unpack.hpp:96) ==1775== by 0x10AA5F: next (unpack.hpp:92) ==1775== by 0x10AA5F: next (unpack.hpp:109) ==1775== by 0x10AA5F: main (main.cpp:155) ==1775== Block was alloc'd at ==1775== at 0x4849013: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==1775== by 0x10ACA2: push (cpp11_zone.hpp:58) ==1775== by 0x10ACA2: push_finalizer (cpp11_zone.hpp:270) ==1775== by 0x10ACA2: flush_zone (unpack.hpp:136) ==1775== by 0x10ACA2: release_zone (unpack.hpp:114) ==1775== by 0x10ACA2: next (unpack.hpp:96) ==1775== by 0x10ACA2: next (unpack.hpp:92) ==1775== by 0x10ACA2: next (unpack.hpp:109) ==1775== by 0x10ACA2: main (main.cpp:155) ==1775== ==1775== Invalid read of size 8 ==1775== at 0x10AAB4: operator() (cpp11_zone.hpp:33) ==1775== by 0x10AAB4: clear (cpp11_zone.hpp:49) ==1775== by 0x10AAB4: ~finalizer_array (cpp11_zone.hpp:43) ==1775== by 0x10AAB4: ~zone (cpp11_zone.hpp:196) ==1775== by 0x10AAB4: operator() (unique_ptr.h:85) ==1775== by 0x10AAB4: reset (unique_ptr.h:182) ==1775== by 0x10AAB4: reset (unique_ptr.h:456) ==1775== by 0x10AAB4: next (unpack.hpp:96) ==1775== by 0x10AAB4: next (unpack.hpp:92) ==1775== by 0x10AAB4: next (unpack.hpp:109) ==1775== by 0x10AAB4: main (main.cpp:155) ==1775== Address 0x4dea100 is 0 bytes inside a block of size 24 free'd ==1775== at 0x484BB6F: operator delete(void*, unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) .... ==1775== ==1775== ==1775== HEAP SUMMARY: ==1775== in use at exit: 0 bytes in 0 blocks ==1775== total heap usage: 16 allocs, 19 frees, 148,190 bytes allocated ==1775== ==1775== All heap blocks were freed -- no leaks are possible ==1775== ==1775== For lists of detected and suppressed errors, rerun with: -s ==1775== ERROR SUMMARY: 38 errors from 12 contexts (suppressed: 0 from 0) ```
valgrind output after ``` $ g++ main.cpp -I ../../lib/ -O3 -g $ valgrind ./a.out ==1797== Memcheck, a memory error detector ==1797== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==1797== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info ==1797== Command: ./a.out ==1797== "Log message ... 1" "Log message ... 2" "Log message ... 3" ==1797== ==1797== HEAP SUMMARY: ==1797== in use at exit: 0 bytes in 0 blocks ==1797== total heap usage: 16 allocs, 16 frees, 148,190 bytes allocated ==1797== ==1797== All heap blocks were freed -- no leaks are possible ==1797== ==1797== For lists of detected and suppressed errors, rerun with: -s ==1797== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```

Checked with g++ 11.4.0

redboltz commented 9 months ago

It seems that sCI reports errors. Could you fix it? Maybe zlib version updating required.

Arenoros commented 5 months ago

any idea why the tests failed?

error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?

redboltz commented 5 months ago

any idea why the tests failed?

error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?

I updated boost and osx compiler. I just merged #1122 . Please try rebasing your PR from the new cpp_master.