Skip to content

Commit

Permalink
leak fixed the right way
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Cavalcanti committed Feb 8, 2015
1 parent d3ad7cd commit 45bbb5e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/wax_instance.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
static int pcallUserdata(lua_State *L, id self, SEL selector);

void ** sharedMemoryForArgs;
int sharedMemoryNArgs;

static const struct luaL_Reg metaFunctions[] = {
{"__index", __index},
Expand Down Expand Up @@ -564,7 +565,16 @@ static int customInitMethodClosure(lua_State *L) {

void myForwardInvocation(id self, SEL _cmd, NSInvocation * inv){
NSInteger n = [[inv methodSignature] numberOfArguments];
sharedMemoryForArgs = calloc(sizeof(void *), n);
if(sharedMemoryNArgs>0 && sharedMemoryForArgs){
for(int i = 0 ; i < sharedMemoryNArgs; i++){
if(sharedMemoryForArgs[i]){
free(sharedMemoryForArgs[i]);
}
}
free(sharedMemoryForArgs);
}
sharedMemoryNArgs = (int)n-2;
sharedMemoryForArgs = calloc(sizeof(void *), n-2);
void * value = nil;
for (int i = 0; i < n-2; i++) {
id __unsafe_unretained arg;
Expand Down Expand Up @@ -600,7 +610,6 @@ void myForwardInvocation(id self, SEL _cmd, NSInvocation * inv){
}
}


#pragma mark Override Methods
#pragma mark ---------------------

Expand Down

0 comments on commit 45bbb5e

Please sign in to comment.