Re: [PATCH 06/28] fix py-evtregistry.c refcount bug

Tom Tromey
2013-04-22T18:26:29Z

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> The checker found a refcounting bug in py-evtregistry.c.
Tom> This fixes it. It also adds CPYCHECKER_STEALS_REFERENCE_TO_ARG.
Tom> I think I meant to split this patch and forgot, sorry about that.

I went ahead and split this.

Tom

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fix py-evtregistry.c refcount bug --]
[-- Type: text/x-patch, Size: 897 bytes --]

From c2dee2f4e0c0665fe308e596969d5bb3076fdc09 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 22 Apr 2013 12:23:19 -0600
Subject: [PATCH 07/33] fix py-evtregistry.c refcount bug

The checker found a refcounting bug in py-evtregistry.c.

* py-evtregistry.c (create_event_object): Decref
eventregistry_object if PyList_New fails.
---
gdb/python/py-evtregistry.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index c8003af..05c8586 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -89,7 +89,10 @@ create_eventregistry_object (void)

eventregistry_obj->callbacks = PyList_New (0);
if (!eventregistry_obj->callbacks)
- return NULL;
+ {
+ Py_DECREF (eventregistry_obj);
+ return NULL;
+ }

return eventregistry_obj;
}
--
1.8.1.4

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: add CPYCHECKER_STEALS_REFERENCE_TO_ARG --]
[-- Type: text/x-patch, Size: 1958 bytes --]

From 8091b73a70c56a7be474c23efa2a8ab598a7b186 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Mon, 22 Apr 2013 12:23:48 -0600
Subject: [PATCH 08/33] add CPYCHECKER_STEALS_REFERENCE_TO_ARG

The checker provides an attribute that can be used to indicate that a
function steals a reference to an argument. This patch adds a macro
for this attribute to gdb and changes one spot to use it.

* python/py-event.h (evpy_emit_event): Use
CPYCHECKER_STEALS_REFERENCE_TO_ARG.
* python/python-internal.h (CPYCHECKER_STEALS_REFERENCE_TO_ARG):
New macro.
---
gdb/python/py-event.h | 3 ++-
gdb/python/python-internal.h | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 970595b..1db8bd2 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -106,7 +106,8 @@ extern int emit_continue_event (ptid_t ptid);
extern int emit_exited_event (const LONGEST *exit_code, struct inferior *inf);

extern int evpy_emit_event (PyObject *event,
- eventregistry_object *registry);
+ eventregistry_object *registry)
+ CPYCHECKER_STEALS_REFERENCE_TO_ARG (1);

extern PyObject *create_event_object (PyTypeObject *py_type);
extern PyObject *create_thread_event_object (PyTypeObject *py_type);
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 394a148..5fbb472 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -34,6 +34,13 @@
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#endif

+#ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
+#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) \
+ __attribute__ ((cpychecker_steals_reference_to_arg (n)))
+#else
+#define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n)
+#endif
+
#include <stdio.h>

/* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t
--
1.8.1.4