Skip to content

Commit

Permalink
Merge pull request #2732 from nvt/fix-heapmem
Browse files Browse the repository at this point in the history
Minor heapmem fixes.
  • Loading branch information
nfi authored Oct 6, 2023
2 parents f256928 + 73d69f6 commit aaad6db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
3 changes: 2 additions & 1 deletion os/lib/heapmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ static size_t heap_usage;
static chunk_t *first_chunk = (chunk_t *)heap_base;
static chunk_t *free_list;

#define IN_HEAP(ptr) ((char *)(ptr) >= (char *)heap_base) && \
#define IN_HEAP(ptr) ((ptr) != NULL && \
(char *)(ptr) >= (char *)heap_base) && \
((char *)(ptr) < (char *)heap_base + heap_usage)

/* extend_space: Increases the current footprint used in the heap, and
Expand Down
11 changes: 5 additions & 6 deletions os/lib/heapmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
* The heapmem module is a dynamic heap memory allocator similar to
* malloc() in standard C. The heap memory is managed in a block of
* static memory, whose size is determined at compile-time by setting
* HEAPMEM_CONF_ARENA_SIZE parameter. By default, the heap memory is
* only 1 bytes, which entails that this parameter must be set
* explicitly in order to be possible to use this module.
* the HEAPMEM_CONF_ARENA_SIZE parameter.
*
* Each allocated memory object is referred to as a "chunk". The
* allocator manages free chunks in a double-linked list. While this
Expand All @@ -60,7 +58,7 @@
* standard C function calloc().
*
* \note Dynamic memory should be used carefully on
* memory-constrained, embedded systems, because fragmentation
* memory-constrained embedded systems, because fragmentation
* may be induced through various allocation/deallocation
* patterns, and no guarantees are given regarding the
* availability of memory.
Expand Down Expand Up @@ -105,7 +103,8 @@ typedef uint8_t heapmem_zone_t;
* \param name A pointer to a chunk that has been allocated using
* heapmem_alloc() or heapmem_realloc().
* \param zone_size The number of bytes to reserve for the zone.
* \return A zone ID if the allocation succeeds, or HEAPMEM_ZONE_INVALID if it fails.
* \return A zone ID if the allocation succeeds, or
* HEAPMEM_ZONE_INVALID if it fails.
*/
heapmem_zone_t heapmem_zone_register(const char *name, size_t zone_size);
/*****************************************************************************/
Expand Down Expand Up @@ -177,7 +176,7 @@ void *heapmem_realloc(void *ptr, size_t size);
* \return A boolean indicating whether the memory could be deallocated.
*
* \note If ptr is NULL, this function will return immediately without
* without performing any action.
* performing any action.
*
* \sa heapmem_alloc
* \sa heapmem_realloc
Expand Down

0 comments on commit aaad6db

Please sign in to comment.