summaryrefslogtreecommitdiff
path: root/MLKCompiledClosure.m
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 14:28:22 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 14:28:22 +0200
commitdfe50b2e72ddbd0148870748975f00e7fc662314 (patch)
tree65698a358024d4f82b4235b3944f53cfe5bc0868 /MLKCompiledClosure.m
parentefa4eaca17fd6c1e19210f069fe9963c185fa200 (diff)
MLKCompiledClosure: Always indirect through a function pointer before doing a call.
Diffstat (limited to 'MLKCompiledClosure.m')
-rw-r--r--MLKCompiledClosure.m14
1 files changed, 11 insertions, 3 deletions
diff --git a/MLKCompiledClosure.m b/MLKCompiledClosure.m
index 35c8aca..b70fa03 100644
--- a/MLKCompiledClosure.m
+++ b/MLKCompiledClosure.m
@@ -38,7 +38,10 @@
_data = data;
_dataLength = dataLength;
- _code = code;
+ _ownPointer = YES;
+
+ _code = malloc (sizeof (id (*)()));
+ *_code = code;
for (i = 0; i < _dataLength; i++)
{
@@ -86,7 +89,7 @@
format:@"FFI type is invalid (this is probably a bug)."];
}
- ffi_call (&cif, FFI_FN (_code), &return_value, (void**)argv);
+ ffi_call (&cif, FFI_FN (*_code), &return_value, (void**)argv);
// FIXME
return [NSArray arrayWithObject:nullify(return_value)];
@@ -108,11 +111,16 @@
[super dealloc];
- // FIXME: Decrease refcount of _code.
+ // FIXME: Decrease refcount of *_code. Note: When releasing *_code,
+ // also release _code regardless of whether we own it.
+
for (i = 0; i < _dataLength; i++)
{
LRELEASE (_data[i]);
}
free (_data);
+
+ if (_ownPointer)
+ free (_code);
}
@end