Changeset 2156


Ignore:
Timestamp:
Jul 3, 2005, 12:03:14 AM (20 years ago)
Author:
bird
Message:

malloc and realloc must set errno to ENOMEM on failure.

Location:
trunk/src/emx/src/lib/malloc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/malloc/irealloc.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2155 r2156  
    1010#include <sys/fmutex.h>
    1111#include <emx/umalloc.h>
     12#include <errno.h>
    1213
    1314static void *_um_crumb_expand (struct _um_crate *crate,
     
    297298  struct _um_hdr *hdr;
    298299  _umagic *parent;
     300  void *ret;
    299301
    300302  if (block == NULL)
     
    310312    {
    311313      _um_abort ("Tried to free block twice! (realloc)");
     314      errno = EINVAL;
    312315      return NULL;
    313     } 
     316    }
    314317  parent = _PTR_FROM_UMINT (hdr->parent, _umagic);
    315318  switch (*parent)
    316319    {
    317320    case _UM_MAGIC_CRATE:
    318       return _um_crumb_realloc ((struct _um_crate *)parent,
    319                                 _UM_CRUMB_FROM_BLOCK (block), new_size,
    320                                 align, flags);
     321      ret = _um_crumb_realloc ((struct _um_crate *)parent,
     322                               _UM_CRUMB_FROM_BLOCK (block), new_size,
     323                               align, flags);
    321324      break;
     325
    322326    case _UM_MAGIC_SEG:
    323       return _um_lump_realloc ((struct _um_seg *)parent,
    324                                _UM_LUMP_FROM_BLOCK (block), new_size,
    325                                align, flags);
     327      ret = _um_lump_realloc ((struct _um_seg *)parent,
     328                              _UM_LUMP_FROM_BLOCK (block), new_size,
     329                              align, flags);
     330      break;
     331
    326332    default:
    327333      {
    328334        _um_abort ("Corrupt heap or passing wrong pointer to realloc! (bad parent magic)");
     335        errno = EINVAL;
    329336        return NULL;
    330337      }
    331338    }
    332 }
     339  if (ret)
     340    return ret;
     341  errno = ENOMEM;
     342  return NULL;
     343}
  • trunk/src/emx/src/lib/malloc/umalloc.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2155 r2156  
    99#include <sys/fmutex.h>
    1010#include <emx/umalloc.h>
     11#include <errno.h>
    1112
    1213void *_umalloc (Heap_t h, size_t size)
     
    1819  assert (h->magic == _UM_MAGIC_HEAP);
    1920  if (h->magic != _UM_MAGIC_HEAP)
    20     return NULL;
     21    {
     22      errno = EINVAL;
     23      return NULL;
     24    }
    2125
    2226  _um_heap_lock (h);
     
    2630  block = _um_alloc_no_lock (h, size, align, flags);
    2731  _um_heap_unlock (h);
    28   return block;
     32  if (block)
     33      return block;
     34  errno = ENOMEM;
     35  return NULL;
    2936}
Note: See TracChangeset for help on using the changeset viewer.