Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix cfunc.c
  • Loading branch information
funny-falcon committed Jan 6, 2012
commit 9f4bcbec9c69f3cc2d8c4e12dacc63371dd4ae9a
4 changes: 2 additions & 2 deletions ext/dl/cfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dlcfunc_free(void *ptr)
{
struct cfunc_data *data = ptr;
if( data->name ){
xfree(data->name);
free(data->name);
}
xfree(data);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ rb_dlcfunc_initialize(int argc, VALUE argv[], VALUE self)
sname = NIL_P(name) ? NULL : StringValuePtr(name);

TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, data);
if( data->name ) xfree(data->name);
if( data->name ) free(data->name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think data->name is not allocated anything, isn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes. This line is a my mistake, which is not exposed cause data->name is not allocated at this point.
This is mistake, cause I already override strdup by including <ruby/util.h>, so that I should revert to use xfree.

By the way: we could call #initialize on a live object, so that data->name could be initialized.

data->ptr = saddr;
data->name = sname ? strdup(sname) : 0;
data->type = NIL_P(type) ? DLTYPE_VOID : NUM2INT(type);
Expand Down