-
Notifications
You must be signed in to change notification settings - Fork 188
Callback on include #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: