Skip to content

Commit

Permalink
Merge pull request iovisor#1585 from palmtenor/usdt_destruct
Browse files Browse the repository at this point in the history
Destruct USDTContext correctly in Python
  • Loading branch information
4ast committed Feb 10, 2018
2 parents e01c993 + e060464 commit cbfd285
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cc/usdt/usdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,10 @@ void *bcc_usdt_new_frompath(const char *path) {
}

void bcc_usdt_close(void *usdt) {
USDT::Context *ctx = static_cast<USDT::Context *>(usdt);
delete ctx;
if (usdt) {
USDT::Context *ctx = static_cast<USDT::Context *>(usdt);
delete ctx;
}
}

int bcc_usdt_enable_probe(void *usdt, const char *probe_name,
Expand Down
3 changes: 3 additions & 0 deletions src/python/bcc/usdt.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ def __init__(self, pid=None, path=None):
raise USDTException(
"either a pid or a binary path must be specified")

def __del__(self):
lib.bcc_usdt_close(self.context)

def enable_probe(self, probe, fn_name):
if lib.bcc_usdt_enable_probe(self.context, probe.encode('ascii'),
fn_name.encode('ascii')) != 0:
Expand Down

0 comments on commit cbfd285

Please sign in to comment.