-
Notifications
You must be signed in to change notification settings - Fork 20
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
Issue#4 #7
base: master
Are you sure you want to change the base?
Issue#4 #7
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…e class to avoid pointer dereferencement because of potential garbage collection
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,14 @@ def register_callback(self, callback, event_type=NFCT_T_ALL, data=None): | |
return: NFCT_CB_CONTINUE, NFCT_CB_FAILURE, NFCT_CB_STOP, | ||
or NFCT_CB_STOLEN (like continue, but ct is not freed). | ||
""" | ||
self.event_type = event_type | ||
self.callback = nfct_callback_t(callback) | ||
self.callback_arg = data | ||
nfct_callback_register(self.handle, event_type, self.callback, self.callback_arg) | ||
ret = nfct_callback_register(self.handle, self.event_type, self.callback, self.callback_arg) | ||
if ret == -1: | ||
self._error('nfct_callback_register') | ||
elif ret != 0: | ||
self._error('nfct_callback_register unknown return code') | ||
|
||
def unregister_callback(self): | ||
"""Unregister callback""" | ||
|
@@ -90,9 +95,13 @@ def query(self, command, argument): | |
|
||
May raise a RuntimeError. | ||
""" | ||
ret = nfct_query(self.handle, command, argument) | ||
if ret != 0: | ||
self.query_type = command | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indenting looks weird here ? That should confuse Python. |
||
|
||
ret = nfct_query(self.handle, self.query_type, byref(argument)) | ||
if ret == -1: | ||
self._error('nfct_query') | ||
elif ret != 0: | ||
self._error('nfct_query unknown return code') | ||
|
||
def catch(self, callback): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,12 @@ def __init__(self, subsys, subscriptions): | |
self.conntrack = None | ||
self.handle = None | ||
|
||
self.subsys = subsys | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is it use ? Do you plan to do something with it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used on next list (open a conntrack handler), however it is not really used in the class. The reason is that I saw several reports of dereferencements of data when using python clib because the garbage collector lost track of a variable used in the c library and cleaned it up. |
||
self.subscriptions = subscriptions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
# Open a conntrack handler | ||
self.handle = nfct_open(subsys, subscriptions) | ||
if not self.handle: | ||
self.handle = nfct_open(self.subsys, self.subscriptions) | ||
if self.handle == None: | ||
self._error('nfct_new') | ||
|
||
def _error(self, func_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.
Bad indent here too.