libeg/lodepng_xtra.c
void* lodepng_malloc(size_t size) {
   void *ptr;

   ptr = AllocateZeroPool(size + sizeof(size_t));
   if (ptr) {
      *(size_t *) ptr = size;
      return ((size_t *) ptr) + 1;
   } else {
      return NULL;
   }
}
// EFI's equivalent of realloc requires the original buffer's size as an
// input parameter, which the standard libc realloc does not require. Thus,
// I've modified lodepng_malloc() to allocate more memory to store this data,
// and lodepng_realloc() can then read it when required. Because the size is
// stored at the start of the allocated area, these functions are NOT
// interchangeable with the standard EFI functions; memory allocated via
// lodepng_malloc() should be freed via lodepng_free(), and myfree() should
// NOT be used with memory allocated via AllocatePool() or AllocateZeroPool()!
EFI's equivalent of realloc requires the original buffer's size as an
input parameter, which the standard libc realloc does not require. Thus,
I've modified lodepng_malloc() to allocate more memory to store this data,
and lodepng_realloc() can then read it when required. Because the size is
stored at the start of the allocated area, these functions are NOT
interchangeable with the standard EFI functions; memory allocated via
lodepng_malloc() should be freed via lodepng_free(), and myfree() should
NOT be used with memory allocated via AllocatePool() or AllocateZeroPool()!
EFI ' s equivalent of realloc requires the original buffer ' s size as an input parameter which the standard libc realloc does not require . Thus I ' ve modified lodepng_malloc () to allocate more memory to store this data and lodepng_realloc () can then read it when required . Because the size is stored at the start of the allocated area these functions are NOT interchangeable with the standard EFI functions ; memory allocated via lodepng_malloc () should be freed via lodepng_free () and myfree () should NOT be used with memory allocated via AllocatePool () or AllocateZeroPool () !
void* lodepng_malloc(size_t size) {
   void *ptr;
   ptr = AllocateZeroPool(size + sizeof(size_t));
   if (ptr) {
      *(size_t *) ptr = size;
      return ((size_t *) ptr) + 1;
   } else {
      return NULL;
   }
}
void * lodepng_malloc ( size_t size ) { void * ptr ; ptr = AllocateZeroPool ( size + sizeof ( size_t ) ) ; if ( ptr ) { * ( size_t * ) ptr = size ; return ( ( size_t * ) ptr ) + 1 ; } else { return NULL ; } }
EFI's equivalent of realloc requires the original buffer's size as an
input parameter, which the standard libc realloc does not require.
EFI ' s equivalent of realloc requires the original buffer ' s size as an input parameter which the standard libc realloc does not require .