public
Created

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
commit 32f8d2ec532aaacfc82e85be49f01b89c847ed23
Author: Kyle Ambroff <kambroff@jawbone.com>
Date: Wed Jan 16 22:53:01 2013 -0800
 
Fix leak of list objects and two instances where facts are leaked.
 
diff --git a/clipsmodule.c b/clipsmodule.c
index 2275921..5c0d81d 100644
--- a/clipsmodule.c
+++ b/clipsmodule.c
@@ -739,6 +739,12 @@ typedef struct {
clips_fact_value(e) = p; \
} while(0)
+/* Move a pointer to a CLIPS fact without incrementing the reference count.
+ Same as clips_fact_assign(), except ownership is being transfered. */
+#define clips_fact_move(e, p) do { \
+ clips_fact_value(e) = p; \
+ } while(0)
+
/* lock/unlock a fact object */
#define clips_fact_locked(v) (((clips_FactObject *)(v))->locked)
#define clips_fact_lock(v) do { \
@@ -1604,6 +1610,7 @@ PyObject *i_do2py_e(void *env, DATA_OBJECT *o) {
PyList_SET_ITEM(q, i, p1);
}
p = Py_BuildValue("(iO)", t, q);
+ Py_DECREF(q);
break;
case INSTANCE_ADDRESS:
ptr = DOPToPointer(o);
@@ -2989,7 +2996,7 @@ static PyObject *g_assertFact(PyObject *self, PyObject *args) {
FAIL();
}
clips_fact_readonly(q) = TRUE;
- clips_fact_assign(q, ptr);
+ clips_fact_move(q, ptr);
clips_fact_lock(q);
CHECK_VALID_FACT(q);
RETURN_PYOBJECT(q);
@@ -3028,7 +3035,7 @@ static PyObject *g_assertString(PyObject *self, PyObject *args) {
FAIL();
}
clips_fact_readonly(p) = TRUE;
- clips_fact_assign(p, ptr);
+ clips_fact_move(p, ptr);
clips_fact_lock(p);
CHECK_VALID_FACT(p);
RETURN_PYOBJECT(p);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.