Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unpack example from quickstart segfaults #1100 #1103

Open
wants to merge 5 commits into
base: cpp_master
Choose a base branch
from

Conversation

Arenoros
Copy link

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
Copy link
Contributor

redboltz commented Feb 6, 2024

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

@Arenoros
Copy link
Author

any idea why the tests failed?

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

@redboltz
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants