Skip to content

Commit 1d42d17

Browse files
authored
Make all dynamic memory allocations via core API functions in jerry-ext (#4480)
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 [email protected]
1 parent b313824 commit 1d42d17

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
@@ -157,7 +157,8 @@ jerryx_handle_scope_alloc (void)
157157
}
158158
else
159159
{
160-
jerryx_handle_scope_dynamic_t *dy_scope = malloc (sizeof (jerryx_handle_scope_dynamic_t));
160+
jerryx_handle_scope_dynamic_t *dy_scope;
161+
dy_scope = (jerryx_handle_scope_dynamic_t *) jerry_heap_alloc (sizeof (jerryx_handle_scope_dynamic_t));
161162
JERRYX_ASSERT (dy_scope != NULL);
162163
dy_scope->child = NULL;
163164

@@ -216,7 +217,7 @@ jerryx_handle_scope_free (jerryx_handle_scope_t *scope)
216217
{
217218
dy_scope->parent->child = dy_scope->child;
218219
}
219-
free (dy_scope);
220+
jerry_heap_free (dy_scope, sizeof (jerryx_handle_scope_dynamic_t));
220221
return;
221222
}
222223
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jerryx_handle_scope_release_handles (jerryx_handle_scope scope)
4848
{
4949
jerry_release_value (a_handle->jval);
5050
jerryx_handle_t *sibling = a_handle->sibling;
51-
free (a_handle);
51+
jerry_heap_free (a_handle, sizeof (jerryx_handle_t));
5252
a_handle = sibling;
5353
}
5454
scope->handle_ptr = NULL;
@@ -134,7 +134,7 @@ jerryx_hand_scope_escape_handle_from_prelist (jerryx_handle_scope scope, size_t
134134
jerryx_handle_t *handle = scope->handle_ptr;
135135
scope->handle_ptr = handle->sibling;
136136
scope->handle_prelist[idx] = handle->jval;
137-
free (handle);
137+
jerry_heap_free (handle, sizeof (jerryx_handle_t));
138138
return jval;
139139
}
140140

@@ -313,7 +313,7 @@ jerryx_handle_scope_add_handle_to (jerryx_handle_t *handle, jerryx_handle_scope
313313
{
314314
++scope->prelist_handle_count;
315315
jerry_value_t jval = handle->jval;
316-
free (handle);
316+
jerry_heap_free (handle, sizeof (jerryx_handle_t));
317317
scope->handle_prelist[prelist_handle_count] = jval;
318318
return jval;
319319
}
@@ -341,7 +341,7 @@ jerryx_create_handle_in_scope (jerry_value_t jval, jerryx_handle_scope scope)
341341
++scope->prelist_handle_count;
342342
return jval;
343343
}
344-
jerryx_handle_t *handle = malloc (sizeof (jerryx_handle_t));
344+
jerryx_handle_t *handle = (jerryx_handle_t *) jerry_heap_alloc (sizeof (jerryx_handle_t));
345345
JERRYX_ASSERT (handle != NULL);
346346
handle->jval = jval;
347347

0 commit comments

Comments
 (0)