mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Returning NULL from mem_heap_alloc_block if requested block size is zero.
This commit is contained in:
parent
9b1fff1d8b
commit
1e0eea3d73
@ -409,8 +409,8 @@ mem_init_block_header (uint8_t *first_chunk_p, /**< address of the first
|
||||
* It is supposed, that all short-term allocation is used during relatively short discrete sessions.
|
||||
* After end of the session all short-term allocated regions are supposed to be freed.
|
||||
*
|
||||
* @return pointer to allocated memory block - if allocation is successful,\n
|
||||
* NULL - if there is not enough memory.
|
||||
* @return pointer to allocated memory block - if allocation is successful,
|
||||
* NULL - if requested region size is zero or if there is not enough memory.
|
||||
*/
|
||||
void*
|
||||
mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to allocate in bytes */
|
||||
@ -421,6 +421,11 @@ mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to all
|
||||
|
||||
mem_check_heap ();
|
||||
|
||||
if (size_in_bytes == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (alloc_term == MEM_HEAP_ALLOC_LONG_TERM)
|
||||
{
|
||||
block_p = mem_heap.first_block_p;
|
||||
|
||||
@ -88,14 +88,14 @@ extern void mem_heap_stats_reset_peak (void);
|
||||
*/
|
||||
#define MEM_DEFINE_LOCAL_ARRAY(var_name, number, type) \
|
||||
{ \
|
||||
type *var_name = ((number > 0) \
|
||||
? mem_heap_alloc_block ((number) * sizeof (type), MEM_HEAP_ALLOC_SHORT_TERM) \
|
||||
: NULL); \
|
||||
size_t var_name ## ___size = (size_t) (number) * sizeof (type); \
|
||||
type *var_name = mem_heap_alloc_block (var_name ## ___size, MEM_HEAP_ALLOC_SHORT_TERM); \
|
||||
\
|
||||
if (var_name == NULL) \
|
||||
if (number > 0 \
|
||||
&& var_name == NULL) \
|
||||
{ \
|
||||
jerry_exit (ERR_OUT_OF_MEMORY); \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the previously defined local array variable, freeing corresponding block on the heap,
|
||||
@ -104,8 +104,14 @@ extern void mem_heap_stats_reset_peak (void);
|
||||
#define MEM_FINALIZE_LOCAL_ARRAY(var_name) \
|
||||
if (var_name != NULL) \
|
||||
{ \
|
||||
JERRY_ASSERT (var_name ## ___size != 0); \
|
||||
\
|
||||
mem_heap_free_block (var_name); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
JERRY_ASSERT (var_name ## ___size == 0); \
|
||||
} \
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user