Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/malloc.c

    r0a2c96c ra22c62f  
    3434#include <bitops.h>
    3535#include <mm/slab.h>
    36 #include <mem.h>
     36#include <memw.h>
    3737#include <main/main.h> // malloc_init()
    3838#include <macros.h>
     
    190190                return NULL;
    191191
    192         void *obj = mem_alloc(alignof(max_align_t), size + _offset) + _offset;
     192        void *obj = mem_alloc(alignof(max_align_t), size + _offset);
     193        if (!obj)
     194                return NULL;
     195
     196        obj += _offset;
    193197
    194198        /* Remember the allocation size just before the object. */
     
    205209         * slab_free() will detect it and panic.
    206210         */
    207         size_t size = ((size_t *) obj)[-1];
    208         mem_free(obj - _offset, alignof(max_align_t), size + _offset);
     211        if (obj) {
     212                size_t size = ((size_t *) obj)[-1];
     213                mem_free(obj - _offset, alignof(max_align_t), size + _offset);
     214        }
    209215}
    210216
    211217void *realloc(void *old_obj, size_t new_size)
    212218{
     219        if (new_size == 0)
     220                new_size = 1;
     221
    213222        if (!old_obj)
    214223                return malloc(new_size);
Note: See TracChangeset for help on using the changeset viewer.