Always print an error message in the case when the C object, being wrapped by the Python type failed to destroy. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- src/common.h | 7 +++++-- src/ftracepy-utils.c | 4 ++-- src/ftracepy-utils.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/common.h b/src/common.h index abfda1f..697b327 100644 --- a/src/common.h +++ b/src/common.h @@ -54,8 +54,9 @@ static inline void no_free(void *ptr) #define NO_FREE no_free -static inline void no_destroy(void *ptr) +static inline int no_destroy(void *ptr) { + return 0; } #define NO_DESTROY no_destroy @@ -101,7 +102,9 @@ static int py_type##_init(py_type *self, PyObject *args, PyObject *kwargs) \ static void py_type##_dealloc(py_type *self) \ { \ if (self->destroy) \ - obj_destroy(self->ptrObj); \ + if (obj_destroy(self->ptrObj) < 0) \ + printf("fracepy_error: object '%s' failed to destroy\n",\ + c_type); \ ptr_free(self->ptrObj); \ Py_TYPE(self)->tp_free(self); \ } \ diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index ca7f914..e49132d 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1757,9 +1757,9 @@ PyObject *PyKprobe_probe(PyKprobe *self) return PyUnicode_FromString(self->ptrObj->probe); } -void ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp) +int ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp) { - unregister_kprobe(kp->event); + return tracefs_kprobe_clear_probe(TC_SYS, kp-> event, true); } void ftracepy_kprobe_free(struct ftracepy_kprobe *kp) diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index 9f4c4ba..a6133cf 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -26,7 +26,7 @@ C_OBJECT_WRAPPER_DECLARE(tracefs_instance, PyTfsInstance) struct ftracepy_kprobe; -void ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp); +int ftracepy_kprobe_destroy(struct ftracepy_kprobe *kp); void ftracepy_kprobe_free(struct ftracepy_kprobe *kp); -- 2.30.2