summaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authorttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-05 01:24:13 +0000
committerttate <ttate@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-05 01:24:13 +0000
commite866f76636bf5c9aed728473c40620ee8a301b17 (patch)
tree73092f18b2864c6668d7d5e65dae6f52aeb6105c /ext
parent0ad8e930533b48f66773602d4ab9505dddecbf23 (diff)
downloadruby-e866f76636bf5c9aed728473c40620ee8a301b17.tar.gz
ruby-e866f76636bf5c9aed728473c40620ee8a301b17.tar.xz
ruby-e866f76636bf5c9aed728473c40620ee8a301b17.zip
Multiple call of the initialize.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/dl/handle.c3
-rw-r--r--ext/dl/ptr.c4
-rw-r--r--ext/dl/sym.c2
3 files changed, 9 insertions, 0 deletions
diff --git a/ext/dl/handle.c b/ext/dl/handle.c
index 0ba439701..4b0a12979 100644
--- a/ext/dl/handle.c
+++ b/ext/dl/handle.c
@@ -75,6 +75,9 @@ rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
};
#endif
Data_Get_Struct(self, struct dl_handle, dlhandle);
+ if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
+ dlclose(dlhandle->ptr);
+ }
dlhandle->ptr = ptr;
dlhandle->open = 1;
dlhandle->enable_close = 0;
diff --git a/ext/dl/ptr.c b/ext/dl/ptr.c
index 1a31861c8..149f33e4e 100644
--- a/ext/dl/ptr.c
+++ b/ext/dl/ptr.c
@@ -202,6 +202,10 @@ rb_dlptr_initialize(int argc, VALUE argv[], VALUE self)
if( p ){
Data_Get_Struct(self, struct ptr_data, data);
+ if( data->ptr && data->free ){
+ /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
+ (*(data->free))(data->ptr);
+ }
data->ptr = p;
data->size = s;
data->free = f;
diff --git a/ext/dl/sym.c b/ext/dl/sym.c
index 7e269b7c9..7531c7969 100644
--- a/ext/dl/sym.c
+++ b/ext/dl/sym.c
@@ -158,6 +158,8 @@ rb_dlsym_initialize(int argc, VALUE argv[], VALUE self)
if( saddr ){
Data_Get_Struct(self, struct sym_data, data);
+ if( data->name ) free(data->name);
+ if( data->type ) free(data->type);
data->func = saddr;
data->name = sname ? strdup(sname) : 0;
data->type = stype ? strdup(stype) : 0;