Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions jerry-core/api/jerryscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -5988,7 +5988,8 @@ jerry_arraybuffer_external (uint8_t *buffer_p, /**< the backing store used by th

if (buffer_p != NULL)
{
arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED
| ECMA_ARRAYBUFFER_EXTERNAL;
arraybuffer_pointer_p->buffer_p = buffer_p;
}
}
Expand Down Expand Up @@ -6076,7 +6077,8 @@ jerry_shared_arraybuffer_external (uint8_t *buffer_p, /**< the backing store use

if (buffer_p != NULL)
{
shared_arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED;
shared_arraybuffer_pointer_p->extended_object.u.cls.u1.array_buffer_flags |= ECMA_ARRAYBUFFER_ALLOCATED
| ECMA_ARRAYBUFFER_EXTERNAL;
shared_arraybuffer_pointer_p->buffer_p = buffer_p;
}
}
Expand Down
1 change: 1 addition & 0 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ typedef enum
ECMA_ARRAYBUFFER_HAS_POINTER = (1u << 0), /* ArrayBuffer has a buffer pointer. */
ECMA_ARRAYBUFFER_ALLOCATED = (1u << 1), /* ArrayBuffer memory is allocated */
ECMA_ARRAYBUFFER_DETACHED = (1u << 2), /* ArrayBuffer has been detached */
ECMA_ARRAYBUFFER_EXTERNAL = (1u << 3), /* ArrayBuffer uses a buffer supplied by the user */
} ecma_arraybuffer_flag_t;

/**
Expand Down
7 changes: 6 additions & 1 deletion jerry-core/ecma/operations/ecma-arraybuffer-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ ecma_arraybuffer_release_buffer (ecma_object_t *arraybuffer_p) /**< ArrayBuffer

if (free_callback == NULL)
{
jmem_heap_free_block (arraybuffer_pointer_p->buffer_p, arraybuffer_length);
/* Externally supplied buffers are owned by the caller, so they must not be
* returned to the internal heap. */
if (!(ECMA_ARRAYBUFFER_GET_FLAGS (arraybuffer_p) & ECMA_ARRAYBUFFER_EXTERNAL))
{
jmem_heap_free_block (arraybuffer_pointer_p->buffer_p, arraybuffer_length);
}
return;
}

Expand Down