Callback on include - #58
Conversation
* Still needs compatible yara submodule update once pull request accepted
| py_calling_ns = Py_None; | ||
| } | ||
|
|
||
| PyObject* result = PyObject_CallFunctionObjArgs(callback, |
There was a problem hiding this comment.
The string returned by the callback is never freed. When PyObject_CallFunctionObjArgs returns the reference count for result is >=1 and your code has the ownership for that string. In order to let the garbage collector free the string you must do a Py_DECREF at some point.
The problem here is that you can't do it in yara_include_callback, because then you are returning to YARA a string that could be freed by the garbage collector at any time. But if you can't do it here, then where?
|
|
||
| if (include_name != NULL) | ||
| { | ||
| py_incl_name = PY_STRING(include_name); |
There was a problem hiding this comment.
You must do a Py_DECREF(py_incl_name) when you are done with the Python string in order to let the garbage collector free the memory. The same applies to py_calling_fn and py_calling_ns.
| py_calling_ns = Py_None; | ||
| } | ||
|
|
||
| PyObject* result = PyObject_CallFunctionObjArgs(callback, |
There was a problem hiding this comment.
You must do Py_INCREF(callback) before PyObject_CallFunctionObjArgs and Py_DECREF(callback) after it.
| PyObject* py_calling_fn = NULL; | ||
| PyObject* py_calling_ns = NULL; | ||
|
|
||
| if (include_name != NULL) |
There was a problem hiding this comment.
Before calling any Python function you must acquire the global interpreter lock (GIL) with PyGILState_Ensure and release it with PyGILState_Release.
* Fixing errors handling
…to callback_on_include
…efault yara behaviour
|
Closing this PR as #67 fix conflicts and some other issues. |
Python interface for pull request VirusTotal/yara#727
Example usage: