Advertisement
Guest User

Untitled

a guest
Nov 6th, 2010
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. diff --git a/lib/skin_parser/skin_buffer.c b/lib/skin_parser/skin_buffer.c
  2. index 3c0870e..0f72f76 100644
  3. --- a/lib/skin_parser/skin_buffer.c
  4. +++ b/lib/skin_parser/skin_buffer.c
  5. @@ -63,8 +63,8 @@ static unsigned char *buffer_front = NULL;
  6.  #ifdef USE_HOST_MALLOC
  7.  
  8.  struct malloc_object {
  9. -    void* object;
  10.      struct malloc_object *next;
  11. +    char buf[0];
  12.  };
  13.  static struct malloc_object *malloced_head = NULL, *malloced_tail = NULL;
  14.  
  15. @@ -76,7 +76,6 @@ static void skin_free_malloced(void)
  16.      {
  17.          this = obj;
  18.          obj = this->next;
  19. -        free(this->object);
  20.          free(this);
  21.      }
  22.      malloced_head = NULL;
  23. @@ -108,17 +107,16 @@ void* skin_buffer_alloc(size_t size)
  24.      retval = buffer_front;
  25.      buffer_front += size;
  26.  #elif defined(USE_HOST_MALLOC)
  27. -    struct malloc_object *obj = malloc(sizeof (struct malloc_object));
  28. -    if (!obj)
  29. -        return NULL;
  30. -    obj->object = malloc(size);
  31. +    size_t malloc_size = sizeof(struct malloc_object) + size;
  32. +    struct malloc_object *obj = malloc(malloc_size);
  33. +    retval = &obj->buf;
  34.      obj->next = NULL;
  35.      if (malloced_tail == NULL)
  36.          malloced_head = malloced_tail = obj;
  37.      else
  38.          malloced_tail->next = obj;
  39.      malloced_tail = obj;
  40. -    retval = obj->object;
  41. +    
  42.  #else
  43.      retval = malloc(size);
  44.  #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement