mirror of
https://github.com/hanzoai/node-dtrace-provider.git
synced 2026-09-23 23:48:45 +00:00
Free memory allocated during the provider setup process.
Firing probes in one provider, and creating/destroying providers should now not leak memory.
This commit is contained in:
@@ -62,12 +62,9 @@ scope to improve this, with more elaborate argument handling.
|
||||
|
||||
## CAVEATS
|
||||
|
||||
This is the first working version, and there are a number of important
|
||||
cleanups to be made. Creating a provider will leak memory, although
|
||||
firing a probe should not.
|
||||
|
||||
Performance is not where it should be, most especially the
|
||||
disabled-probe effect. Probes are already using the "is-enabled"
|
||||
feature of DTrace, but too much work needs to be done before that's
|
||||
feature of DTrace to control execution of the arguments-gathering
|
||||
callback, but too much work needs to be done before that's
|
||||
checked. Improving this may imply changes to the API shown in the
|
||||
example above.
|
||||
|
||||
+8
-2
@@ -265,7 +265,9 @@ namespace node {
|
||||
|
||||
d->probe = p;
|
||||
provider->AppendProbe(p);
|
||||
probes->AddData(p->Dof(), sizeof(dof_probe_t));
|
||||
void *dof = p->Dof();
|
||||
probes->AddData(dof, sizeof(dof_probe_t));
|
||||
free(dof);
|
||||
probes->entsize = sizeof(dof_probe_t);
|
||||
}
|
||||
|
||||
@@ -326,6 +328,8 @@ namespace node {
|
||||
file->Generate();
|
||||
file->Load();
|
||||
|
||||
provider->file = file;
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
@@ -570,7 +574,9 @@ namespace node {
|
||||
|
||||
size_t offset = sizeof(dof_hdr_t);
|
||||
for (DOFSection *section = this->sections; section != NULL; section = section->next) {
|
||||
(void) memcpy((this->dof + offset), section->Header(), sizeof(dof_sec_t));
|
||||
void *header = section->Header();
|
||||
(void) memcpy((this->dof + offset), header, sizeof(dof_sec_t));
|
||||
free(header);
|
||||
offset += sizeof(dof_sec_t);
|
||||
}
|
||||
|
||||
|
||||
+17
-7
@@ -40,6 +40,10 @@ namespace node {
|
||||
DTraceProbe() {
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
~DTraceProbe() {
|
||||
free(addr);
|
||||
}
|
||||
|
||||
void *Dof();
|
||||
uint32_t ProbeOffset(char *dof, uint8_t argc);
|
||||
@@ -65,10 +69,12 @@ namespace node {
|
||||
|
||||
uint8_t Argc();
|
||||
|
||||
protected:
|
||||
~DTraceProbeDef() {
|
||||
delete probe;
|
||||
delete next;
|
||||
free(name);
|
||||
for (int i = 0; (types[i] != NULL && i < 7); i++)
|
||||
free(types[i]);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -115,9 +121,9 @@ namespace node {
|
||||
void AddData(void *data, size_t length);
|
||||
void *Header();
|
||||
|
||||
protected:
|
||||
~DOFSection() {
|
||||
free(data);
|
||||
delete(next);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -138,9 +144,9 @@ namespace node {
|
||||
void Generate();
|
||||
void Load();
|
||||
|
||||
protected:
|
||||
~DOFFile() {
|
||||
free(dof);
|
||||
delete(sections);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -159,9 +165,8 @@ namespace node {
|
||||
|
||||
int Add(char *string);
|
||||
|
||||
protected:
|
||||
~DOFStrtab() {
|
||||
|
||||
// data freed by superclass
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -175,8 +180,8 @@ namespace node {
|
||||
char *name;
|
||||
DTraceProbeDef *probe_defs;
|
||||
DTraceProbe *probes;
|
||||
DOFFile *file;
|
||||
|
||||
protected:
|
||||
static v8::Handle<v8::Value> New(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> AddProbe(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> Enable(const v8::Arguments& args);
|
||||
@@ -186,10 +191,15 @@ namespace node {
|
||||
name = NULL;
|
||||
probe_defs = NULL;
|
||||
probes = NULL;
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
~DTraceProvider() {
|
||||
// disable provider
|
||||
// disable provider first!
|
||||
|
||||
free(name);
|
||||
delete(file);
|
||||
delete(probe_defs);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user