From: Pedro Alves Date: Thu, 13 Aug 2015 17:56:42 +0000 (+0100) Subject: Fix Python frame unwinder issue caught by Valgrind X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3207396b9532f179bad24a9fb9a83253f3f5144d;p=binutils-gdb.git Fix Python frame unwinder issue caught by Valgrind Valgrind shows: ==17026== Invalid write of size 8 ==17026== at 0x54AA80: pending_frame_invalidate (py-unwind.c:477) ==17026== by 0x5AB934: do_my_cleanups (cleanups.c:155) ==17026== by 0x5AB9AF: do_cleanups (cleanups.c:177) ==17026== by 0x54B009: pyuw_sniffer (py-unwind.c:606) ==17026== by 0x755DAC: frame_unwind_try_unwinder (frame-unwind.c:105) ==17026== by 0x755EEE: frame_unwind_find_by_frame (frame-unwind.c:160) ==17026== by 0x750FFA: compute_frame_id (frame.c:454) ==17026== by 0x753BD6: get_prev_frame_if_no_cycle (frame.c:1781) ==17026== by 0x754292: get_prev_frame_always_1 (frame.c:1955) ==17026== by 0x7542DA: get_prev_frame_always (frame.c:1971) ==17026== by 0x7547BE: get_prev_frame (frame.c:2213) ==17026== by 0x7532BD: unwind_to_current_frame (frame.c:1450) ==17026== Address 0xd27b570 is 16 bytes inside a block of size 32 free'd ==17026== at 0x4A07577: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==17026== by 0x54B276: gdb_Py_DECREF (python-internal.h:185) ==17026== by 0x54B298: py_decref (py-utils.c:34) ==17026== by 0x5AB934: do_my_cleanups (cleanups.c:155) ==17026== by 0x5AB9AF: do_cleanups (cleanups.c:177) ==17026== by 0x54B009: pyuw_sniffer (py-unwind.c:606) ==17026== by 0x755DAC: frame_unwind_try_unwinder (frame-unwind.c:105) ==17026== by 0x755EEE: frame_unwind_find_by_frame (frame-unwind.c:160) ==17026== by 0x750FFA: compute_frame_id (frame.c:454) ==17026== by 0x753BD6: get_prev_frame_if_no_cycle (frame.c:1781) ==17026== by 0x754292: get_prev_frame_always_1 (frame.c:1955) ==17026== by 0x7542DA: get_prev_frame_always (frame.c:1971) ==17026== Simply invalidate the object before releasing it. gdb/ChangeLog: 2015-08-13 Pedro Alves * python/py-unwind.c (pyuw_sniffer): Install the invalidate cleanup after the decref cleanup, not before. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f33faaabbe1..7db4487b70a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2015-08-13 Pedro Alves + + * python/py-unwind.c (pyuw_sniffer): Install the invalidate + cleanup after the decref cleanup, not before. + 2015-08-13 Pierre-Marie de Rodat * ada-lang.c: Include namespace.h diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index b6e8a7531ba..18f8f4d3546 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -537,8 +537,8 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, goto error; ((pending_frame_object *) pyo_pending_frame)->gdbarch = gdbarch; ((pending_frame_object *) pyo_pending_frame)->frame_info = this_frame; - make_cleanup (pending_frame_invalidate, (void *) pyo_pending_frame); make_cleanup_py_decref (pyo_pending_frame); + make_cleanup (pending_frame_invalidate, (void *) pyo_pending_frame); /* Run unwinders. */ if (gdb_python_module == NULL