Public bug reported: I made a simple program that make a thread_safe stack. My program segfault at the end at stack_destroy (line 118) but I can't figure out why. I lauchned it with gdb and it told me that the line 118 did a segfault. Then I used valgrind and valgrind segfaulted.
Steps to reproduce: $ gcc thread_stack.c -Wall -o thread_stack -pthread -g $ valgrind ./thread_stack What I get: $ ./thread_stack ret is 0 ret is 1 make: *** [run] Segmentation fault (core dumped) $ valgrind ./thread_stack ==25938== Memcheck, a memory error detector ==25938== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==25938== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info ==25938== Command: ./thread_stack ==25938== ret is 0 ret is 1 ==25938== Invalid read of size 8 ==25938== at 0x400A5B: stack_destroy (thread_stack.c:118) ==25938== by 0x400CB8: main (thread_stack.c:203) ==25938== Address 0x2f is not stack'd, malloc'd or (recently) free'd ==25938== ==25938== ==25938== Process terminating with default action of signal 11 (SIGSEGV) ==25938== Access not within mapped region at address 0x2F ==25938== at 0x400A5B: stack_destroy (thread_stack.c:118) ==25938== by 0x400CB8: main (thread_stack.c:203) ==25938== If you believe this happened as a result of a stack ==25938== overflow in your program's main thread (unlikely but ==25938== possible), you can try to increase the size of the ==25938== main thread stack using the --main-stacksize= flag. ==25938== The main thread stack size used in this run was 8388608. ==25938== ==25938== HEAP SUMMARY: ==25938== in use at exit: 48 bytes in 1 blocks ==25938== total heap usage: 3 allocs, 2 frees, 80 bytes allocated ==25938== ==25938== LEAK SUMMARY: ==25938== definitely lost: 48 bytes in 1 blocks ==25938== indirectly lost: 0 bytes in 0 blocks ==25938== possibly lost: 0 bytes in 0 blocks ==25938== still reachable: 0 bytes in 0 blocks ==25938== suppressed: 0 bytes in 0 blocks ==25938== Rerun with --leak-check=full to see details of leaked memory ==25938== ==25938== For counts of detected and suppressed errors, rerun with: -v ==25938== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2) Segmentation fault (core dumped) $ gdb thread_stack GNU gdb (GDB) 7.5.91.20130417-cvs-ubuntu Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/blegat/Documents/UCL/q4/os/Examens/thread_stack...done. (gdb) run Starting program: /home/blegat/Documents/UCL/q4/os/Examens/thread_stack warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". ret is 0 ret is 1 Program received signal SIGSEGV, Segmentation fault. 0x0000000000400a5b in stack_destroy (stack=0x7fff) at thread_stack.c:118 118 if (stack->first != NULL) { (gdb) quit A debugging session is active. Inferior 1 [process 25961] will be killed. Quit anyway? (y or n) y ProblemType: Bug DistroRelease: Ubuntu 13.04 Package: valgrind 1:3.8.1-1ubuntu5 ProcVersionSignature: Ubuntu 3.8.0-22.33-generic 3.8.11 Uname: Linux 3.8.0-22-generic x86_64 ApportVersion: 2.9.2-0ubuntu8 Architecture: amd64 Date: Thu Jun 6 20:33:39 2013 InstallationDate: Installed on 2012-04-26 (405 days ago) InstallationMedia: Ubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425) MarkForUpload: True ProcEnviron: TERM=xterm PATH=(custom, no user) XDG_RUNTIME_DIR=<set> LANG=en_US.UTF-8 SHELL=/bin/bash SourcePackage: valgrind UpgradeStatus: Upgraded to raring on 2013-04-27 (40 days ago) ** Affects: valgrind (Ubuntu) Importance: Undecided Status: New ** Tags: amd64 apport-bug raring ** Attachment added: "program that make it crash" https://bugs.launchpad.net/bugs/1188334/+attachment/3696597/+files/thread_stack.c -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/1188334 Title: Valgrind SIGSEV with a weird bug To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/valgrind/+bug/1188334/+subscriptions -- ubuntu-bugs mailing list ubuntu-bugs@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs