From patchwork Thu Aug 13 18:05:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 8186 Received: (qmail 16591 invoked by alias); 13 Aug 2015 18:05:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 16581 invoked by uid 89); 13 Aug 2015 18:05:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 13 Aug 2015 18:05:18 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 91D19C9D2C for ; Thu, 13 Aug 2015 18:05:17 +0000 (UTC) Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7DI5GBh007286 for ; Thu, 13 Aug 2015 14:05:17 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [ob/pushed] Fix Python frame unwinder issue caught by Valgrind Date: Thu, 13 Aug 2015 19:05:15 +0100 Message-Id: <1439489115-21621-1-git-send-email-palves@redhat.com> 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. --- gdb/ChangeLog | 5 +++++ gdb/python/py-unwind.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f33faaa..7db4487 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 b6e8a75..18f8f4d 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