Created
January 24, 2013 19:48
-
-
Save ambroff/4626966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 32f8d2ec532aaacfc82e85be49f01b89c847ed23 | |
Author: Kyle Ambroff <[email protected]> | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment