diff options
| author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-24 21:56:50 +0000 |
|---|---|---|
| committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-24 21:56:50 +0000 |
| commit | 886c186d02c12b7a934bd1033d1c96f0accc93a8 (patch) | |
| tree | cf9df8d4723c48093e139bc4f002b260ea358c8a | |
| parent | a5d3cd4c5cd43a36e2f2232aa1c5e49136696ec1 (diff) | |
| download | ruby-886c186d02c12b7a934bd1033d1c96f0accc93a8.tar.gz ruby-886c186d02c12b7a934bd1033d1c96f0accc93a8.tar.xz ruby-886c186d02c12b7a934bd1033d1c96f0accc93a8.zip | |
* ext/dl/handle.c (rb_dlhandle_close) check return value of dlclose()
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ext/dl/handle.c | 19 | ||||
| -rw-r--r-- | test/dl/test_handle.rb | 13 |
2 files changed, 30 insertions, 2 deletions
diff --git a/ext/dl/handle.c b/ext/dl/handle.c index a9df5d611..eee0cb26b 100644 --- a/ext/dl/handle.c +++ b/ext/dl/handle.c @@ -57,8 +57,21 @@ rb_dlhandle_close(VALUE self) struct dl_handle *dlhandle; TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle); - dlhandle->open = 0; - return INT2NUM(dlclose(dlhandle->ptr)); + if(dlhandle->open) { + dlhandle->open = 0; + int ret = dlclose(dlhandle->ptr); + + /* Check dlclose for successful return value */ + if(ret) { +#if defined(HAVE_DLERROR) + rb_raise(rb_eDLError, dlerror()); +#else + rb_raise(rb_eDLError, "could not close handle"); +#endif + } + return INT2NUM(ret); + } + rb_raise(rb_eDLError, "dlclose() called too many times"); } VALUE @@ -301,3 +314,5 @@ Init_dlhandle(void) rb_define_method(rb_cDLHandle, "disable_close", rb_dlhandle_disable_close, 0); rb_define_method(rb_cDLHandle, "enable_close", rb_dlhandle_enable_close, 0); } + +/* mode: c; tab-with=8; sw=8; ts=8; noexpandtab: */ diff --git a/test/dl/test_handle.rb b/test/dl/test_handle.rb index d46e16c08..fed9da4f8 100644 --- a/test/dl/test_handle.rb +++ b/test/dl/test_handle.rb @@ -2,6 +2,19 @@ require 'test_base' module DL class TestHandle < TestBase + def test_handle_close + handle = DL::Handle.new(LIBC_SO) + assert_equal 0, handle.close + end + + def test_handle_close_twice + handle = DL::Handle.new(LIBC_SO) + handle.close + assert_raises(DL::DLError) do + handle.close + end + end + def test_dlopen_returns_handle assert_instance_of DL::Handle, dlopen(LIBC_SO) end |
