@@ -230,8 +230,10 @@ inline op nqp_native_call_build(out PMC, in PMC, in STR, in STR, in STR, in PMC,
230
230
* presumably a type object).
231
231
*/
232
232
inline op nqp_native_call(out PMC, in PMC, in PMC, in PMC) :base_core {
233
- PMC *args = $4;
234
- PMC *result = PMCNULL;
233
+ PMC *args = $4;
234
+ PMC *result = PMCNULL;
235
+ char **free_strs = NULL;
236
+ INTVAL num_strs = 0;
235
237
INTVAL i;
236
238
237
239
/* Get native call body, so we can locate the call info. */
@@ -282,6 +284,9 @@ inline op nqp_native_call(out PMC, in PMC, in PMC, in PMC) :base_core {
282
284
body->arg_types[i] == DYNCALL_ARG_UTF16STR ? Parrot_utf16_encoding_ptr :
283
285
Parrot_utf8_encoding_ptr);
284
286
dcArgPointer(vm, str);
287
+ if (!free_strs)
288
+ free_strs = mem_sys_allocate(body->num_args * sizeof(char *));
289
+ free_strs[num_strs] = str;
285
290
}
286
291
break;
287
292
case DYNCALL_ARG_CSTRUCT:
@@ -291,7 +296,7 @@ inline op nqp_native_call(out PMC, in PMC, in PMC, in PMC) :base_core {
291
296
dcArgPointer(vm, NULL);
292
297
}
293
298
}
294
-
299
+
295
300
/* Call and process return values. */
296
301
switch (body->ret_type) {
297
302
case DYNCALL_ARG_VOID:
@@ -329,6 +334,13 @@ inline op nqp_native_call(out PMC, in PMC, in PMC, in PMC) :base_core {
329
334
result = $2;
330
335
}
331
336
337
+ /* Free any memory that we need to. */
338
+ if (free_strs) {
339
+ for (i = 0; i < num_strs; i++)
340
+ Parrot_str_free_cstring(free_strs[i]);
341
+ mem_sys_free(free_strs);
342
+ }
343
+
332
344
/* Finally, free call VM. */
333
345
dcFree(vm);
334
346
0 commit comments