Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 6th, 2010  |  syntax: C  |  size: 1.28 KB  |  views: 107  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data