[Xcb] [PATCH 3/3] Garbage collect non replied requests.
Julien Danjou
julien at danjou.info
Tue Jan 19 13:04:26 PST 2010
Signed-off-by: Julien Danjou <julien at danjou.info>
---
src/cookie.c | 5 +++++
src/cookie.h | 3 +++
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/src/cookie.c b/src/cookie.c
index 08b9a75..a931bd5 100644
--- a/src/cookie.c
+++ b/src/cookie.c
@@ -23,6 +23,10 @@ xpybCookie_new(PyTypeObject *self, PyObject *args, PyObject *kw)
static void
xpybCookie_dealloc(xpybCookie *self)
{
+ /* If the reply to the cookie has never been fetched from the wire, do it
+ * right now, otherwise we would leak. */
+ if(!self->reply_fetched && !self->request->is_void)
+ free(xcb_wait_for_reply(self->conn->conn, self->cookie.sequence, NULL));
Py_CLEAR(self->reply);
Py_CLEAR(self->reply_type);
Py_CLEAR(self->request);
@@ -82,6 +86,7 @@ xpybCookie_reply(xpybCookie *self, PyObject *args)
/* Make XCB call */
data = xcb_wait_for_reply(self->conn->conn, self->cookie.sequence, &error);
+ self->reply_fetched = true;
if (xpybError_set(self->conn, error))
return NULL;
if (data == NULL) {
diff --git a/src/cookie.h b/src/cookie.h
index f0e25c0..c0d836e 100644
--- a/src/cookie.h
+++ b/src/cookie.h
@@ -1,6 +1,8 @@
#ifndef XPYB_COOKIE_H
#define XPYB_COOKIE_H
+#include <stdbool.h>
+
#include "conn.h"
#include "request.h"
#include "reply.h"
@@ -12,6 +14,7 @@ typedef struct {
xpybReply *reply;
PyTypeObject *reply_type;
xcb_void_cookie_t cookie;
+ bool reply_fetched;
} xpybCookie;
extern PyTypeObject xpybCookie_type;
--
1.6.6
More information about the Xcb
mailing list