Returning NULL from mem_heap_alloc_block if requested block size is zero.
This commit is contained in:
@@ -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.
|
* 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.
|
* 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
|
* @return pointer to allocated memory block - if allocation is successful,
|
||||||
* NULL - if there is not enough memory.
|
* NULL - if requested region size is zero or if there is not enough memory.
|
||||||
*/
|
*/
|
||||||
void*
|
void*
|
||||||
mem_heap_alloc_block (size_t size_in_bytes, /**< size of region to allocate in bytes */
|
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 ();
|
mem_check_heap ();
|
||||||
|
|
||||||
|
if (size_in_bytes == 0)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (alloc_term == MEM_HEAP_ALLOC_LONG_TERM)
|
if (alloc_term == MEM_HEAP_ALLOC_LONG_TERM)
|
||||||
{
|
{
|
||||||
block_p = mem_heap.first_block_p;
|
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) \
|
#define MEM_DEFINE_LOCAL_ARRAY(var_name, number, type) \
|
||||||
{ \
|
{ \
|
||||||
type *var_name = ((number > 0) \
|
size_t var_name ## ___size = (size_t) (number) * sizeof (type); \
|
||||||
? mem_heap_alloc_block ((number) * sizeof (type), MEM_HEAP_ALLOC_SHORT_TERM) \
|
type *var_name = mem_heap_alloc_block (var_name ## ___size, MEM_HEAP_ALLOC_SHORT_TERM); \
|
||||||
: NULL); \
|
|
||||||
\
|
\
|
||||||
if (var_name == NULL) \
|
if (number > 0 \
|
||||||
|
&& var_name == NULL) \
|
||||||
{ \
|
{ \
|
||||||
jerry_exit (ERR_OUT_OF_MEMORY); \
|
jerry_exit (ERR_OUT_OF_MEMORY); \
|
||||||
} \
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the previously defined local array variable, freeing corresponding block on the heap,
|
* 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) \
|
#define MEM_FINALIZE_LOCAL_ARRAY(var_name) \
|
||||||
if (var_name != NULL) \
|
if (var_name != NULL) \
|
||||||
{ \
|
{ \
|
||||||
|
JERRY_ASSERT (var_name ## ___size != 0); \
|
||||||
|
\
|
||||||
mem_heap_free_block (var_name); \
|
mem_heap_free_block (var_name); \
|
||||||
} \
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
JERRY_ASSERT (var_name ## ___size == 0); \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user