summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-09 04:51:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-09 04:51:38 +0000
commitdfdb8b7372fe6a1902ae7e9213d25705b6824383 (patch)
treebdcc5d159029bab28e80f0ef6f4a770d7aba380d /ext
parent1692e547931a6d6dc9f79ea122878803445644f9 (diff)
fiddle/function.c: fix memory leak on exception
* ext/fiddle/function.c (function_call): fix memory leak when an exception occurs at argument conversion or the function call. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/fiddle/function.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c
index 4c297f7..50366bb 100644
--- a/ext/fiddle/function.c
+++ b/ext/fiddle/function.c
@@ -137,6 +137,7 @@ function_call(int argc, VALUE argv[], VALUE self)
void **values;
VALUE cfunc, types, cPointer;
int i;
+ VALUE alloc_buffer = 0;
cfunc = rb_iv_get(self, "@ptr");
types = rb_iv_get(self, "@args");
@@ -159,8 +160,9 @@ function_call(int argc, VALUE argv[], VALUE self)
}
}
- values = xcalloc((size_t)argc + 1, (size_t)sizeof(void *));
- generic_args = xcalloc((size_t)argc, (size_t)sizeof(fiddle_generic));
+ generic_args = ALLOCV(alloc_buffer,
+ (size_t)(argc + 1) * sizeof(void *) + (size_t)argc * sizeof(fiddle_generic));
+ values = (void **)((char *)generic_args + (size_t)argc * sizeof(fiddle_generic));
for (i = 0; i < argc; i++) {
VALUE type = RARRAY_PTR(types)[i];
@@ -187,8 +189,7 @@ function_call(int argc, VALUE argv[], VALUE self)
rb_funcall(mFiddle, rb_intern("win32_last_error="), 1, INT2NUM(errno));
#endif
- xfree(values);
- xfree(generic_args);
+ ALLOCV_END(alloc_buffer);
return GENERIC2VALUE(rb_iv_get(self, "@return_type"), retval);
}