Skip to content

Commit ab1e7a5

Browse files
committed
Make all dynamic memory allocations via core API functions in jerry-ext
Direct calls to `malloc` and `free` should be avoided, `jerry_heap_alloc` and `jerry_heap_free` should be used in their place. Build-time configuration should decide whether those calls manage dynamic memory on the engine's heap or on the system heap. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
1 parent 5e48363 commit ab1e7a5

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

jerry-ext/handle-scope/handle-scope-allocator.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ jerryx_handle_scope_alloc (void)
156156
}
157157
else
158158
{
159-
jerryx_handle_scope_dynamic_t *dy_scope = malloc (sizeof (jerryx_handle_scope_dynamic_t));
159+
jerryx_handle_scope_dynamic_t *dy_scope;
160+
dy_scope = (jerryx_handle_scope_dynamic_t *) jerry_heap_alloc (sizeof (jerryx_handle_scope_dynamic_t));
160161
JERRYX_HANDLE_SCOPE_ASSERT (dy_scope != NULL);
161162
dy_scope->child = NULL;
162163

@@ -215,7 +216,7 @@ jerryx_handle_scope_free (jerryx_handle_scope_t *scope)
215216
{
216217
dy_scope->parent->child = dy_scope->child;
217218
}
218-
free (dy_scope);
219+
jerry_heap_free (dy_scope, sizeof (jerryx_handle_scope_dynamic_t));
219220
return;
220221
}
221222
/**

jerry-ext/handle-scope/handle-scope.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jerryx_handle_scope_release_handles (jerryx_handle_scope scope)
4545
{
4646
jerry_release_value (a_handle->jval);
4747
jerryx_handle_t *sibling = a_handle->sibling;
48-
free (a_handle);
48+
jerry_heap_free (a_handle, sizeof (jerryx_handle_t));
4949
a_handle = sibling;
5050
}
5151
scope->handle_ptr = NULL;
@@ -131,7 +131,7 @@ jerryx_hand_scope_escape_handle_from_prelist (jerryx_handle_scope scope, size_t
131131
jerryx_handle_t *handle = scope->handle_ptr;
132132
scope->handle_ptr = handle->sibling;
133133
scope->handle_prelist[idx] = handle->jval;
134-
free (handle);
134+
jerry_heap_free (handle, sizeof (jerryx_handle_t));
135135
return jval;
136136
}
137137

@@ -310,7 +310,7 @@ jerryx_handle_scope_add_handle_to (jerryx_handle_t *handle, jerryx_handle_scope
310310
{
311311
++scope->prelist_handle_count;
312312
jerry_value_t jval = handle->jval;
313-
free (handle);
313+
jerry_heap_free (handle, sizeof (jerryx_handle_t));
314314
scope->handle_prelist[prelist_handle_count] = jval;
315315
return jval;
316316
}
@@ -338,7 +338,7 @@ jerryx_create_handle_in_scope (jerry_value_t jval, jerryx_handle_scope scope)
338338
++scope->prelist_handle_count;
339339
return jval;
340340
}
341-
jerryx_handle_t *handle = malloc (sizeof (jerryx_handle_t));
341+
jerryx_handle_t *handle = (jerryx_handle_t *) jerry_heap_alloc (sizeof (jerryx_handle_t));
342342
JERRYX_HANDLE_SCOPE_ASSERT (handle != NULL);
343343
handle->jval = jval;
344344

0 commit comments

Comments
 (0)