summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
authorVasilii Chernov <vchernov@inr.ru>2016-02-15 13:41:25 +0100
committerVasilii Chernov <vchernov@inr.ru>2016-02-15 13:41:25 +0100
commit398e756263502a98a0c1887dcf38f7ef1fafa84b (patch)
tree08383da800a8ea529ddad06648399920c27abbce /pcilib
parenta4f3ac0b00694287e791cd7d753b420976d9f22a (diff)
downloadpcitool-398e756263502a98a0c1887dcf38f7ef1fafa84b.tar.gz
pcitool-398e756263502a98a0c1887dcf38f7ef1fafa84b.tar.bz2
pcitool-398e756263502a98a0c1887dcf38f7ef1fafa84b.tar.xz
pcitool-398e756263502a98a0c1887dcf38f7ef1fafa84b.zip
Fix memory leaks
Add GIL states for int pcilib_script_read and pcilib_script_write functions Correct desctructor for create_pcilib_instance return object
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/property.c7
-rw-r--r--pcilib/py.c16
2 files changed, 20 insertions, 3 deletions
diff --git a/pcilib/property.c b/pcilib/property.c
index a7d1a61..3a7ebb3 100644
--- a/pcilib/property.c
+++ b/pcilib/property.c
@@ -165,7 +165,6 @@ pcilib_property_info_t *pcilib_get_property_list(pcilib_t *ctx, const char *bran
continue;
}
-
dir = (struct dir_hash_s*)malloc(sizeof(struct dir_hash_s));
if (!dir) {
err = PCILIB_ERROR_MEMORY;
@@ -226,6 +225,12 @@ pcilib_property_info_t *pcilib_get_property_list(pcilib_t *ctx, const char *bran
};
}
+
+
+ HASH_ITER(hh, dir_hash, dir, dir_tmp) {
+ HASH_DEL(dir_hash, dir);
+ free(dir);
+ }
HASH_CLEAR(hh, dir_hash);
memset(&info[pos], 0, sizeof(pcilib_property_info_t));
diff --git a/pcilib/py.c b/pcilib/py.c
index e448d21..20fa546 100644
--- a/pcilib/py.c
+++ b/pcilib/py.c
@@ -427,7 +427,9 @@ int pcilib_script_read(pcilib_t *ctx, char* module_name, pcilib_value_t *val)
int err;
+ PyGILState_STATE gstate = PyGILState_Ensure();
PyObject *ret = PyObject_CallMethod(module->py_script_module, "read_from_register", "()");
+ PyGILState_Release(gstate);
if (!ret)
{
printf("Python script error: ");
@@ -436,6 +438,7 @@ int pcilib_script_read(pcilib_t *ctx, char* module_name, pcilib_value_t *val)
}
err = pcilib_set_value_from_pyobject(ctx, ret, val);
+ Py_XDECREF(ret);
if(err)
{
@@ -463,17 +466,26 @@ int pcilib_script_write(pcilib_t *ctx, char* module_name, pcilib_value_t *val)
PyErr_Print();
return PCILIB_ERROR_FAILED;
}
+ PyObject *func_name = PyUnicode_FromString("write_to_register");
- PyObject *ret = PyObject_CallMethodObjArgs(module->py_script_module,
- PyUnicode_FromString("write_to_register"),
+ PyGILState_STATE gstate = PyGILState_Ensure();
+ PyObject *ret = PyObject_CallMethodObjArgs(module->py_script_module,
+ func_name,
input,
NULL);
+ PyGILState_Release(gstate);
+
if (!ret)
{
printf("Python script error: ");
PyErr_Print();
return PCILIB_ERROR_FAILED;
}
+
+ //release objects
+ Py_XDECREF(func_name);
+ Py_XDECREF(ret);
+ Py_XDECREF(input);
return 0;
}