Skip to content

Commit

Permalink
Protect path refs because they are in C heap
Browse files Browse the repository at this point in the history
Fixes #421
  • Loading branch information
mfikes committed Jan 4, 2017
1 parent f3323ad commit d4afad4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion planck-c/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,9 @@ JSValueRef function_list_files(JSContextRef ctx, JSObjectRef function, JSObjectR
size_t buf_len = path_len + strlen(dir->d_name) + 2;
char *buf = malloc(buf_len);
snprintf(buf, buf_len, "%s/%s", path, dir->d_name);
paths[count++] = c_string_to_value(ctx, buf);
JSValueRef path_ref = c_string_to_value(ctx, buf);
paths[count++] = path_ref;
JSValueProtect(ctx, path_ref);
free(buf);

if (count == capacity) {
Expand All @@ -793,6 +795,11 @@ JSValueRef function_list_files(JSContextRef ctx, JSObjectRef function, JSObjectR

JSValueRef rv = JSObjectMakeArray(ctx, count, paths, NULL);

size_t i = 0;
for (i=0; i<count; ++i) {
JSValueUnprotect(ctx, paths[i]);
}

free(path);
free(paths);

Expand Down

0 comments on commit d4afad4

Please sign in to comment.