1. diff --git a/lib/skin_parser/skin_buffer.c b/lib/skin_parser/skin_buffer.c
  2. index 3c0870e..59c6a02 100644
  3. --- a/lib/skin_parser/skin_buffer.c
  4. +++ b/lib/skin_parser/skin_buffer.c
  5. @@ -62,10 +62,14 @@ static unsigned char *buffer_front = NULL;
  6.  
  7. #ifdef USE_HOST_MALLOC
  8.  
  9. +#define MALLOC_BLOCK_SIZE (4*1024)
  10. struct malloc_object {
  11. - void* object;
  12. + size_t remaining;
  13. + char *start;
  14. struct malloc_object *next;
  15. + char buf[];
  16. };
  17. +#define MALLOC_FREE_SPACE (MALLOC_BLOCK_SIZE - sizeof(struct malloc_object) - 32)
  18. static struct malloc_object *malloced_head = NULL, *malloced_tail = NULL;
  19.  
  20. static void skin_free_malloced(void)
  21. @@ -76,7 +80,6 @@ static void skin_free_malloced(void)
  22. {
  23. this = obj;
  24. obj = this->next;
  25. - free(this->object);
  26. free(this);
  27. }
  28. malloced_head = NULL;
  29. @@ -100,25 +103,37 @@ void skin_buffer_init(char* buffer, size_t size)
  30. void* skin_buffer_alloc(size_t size)
  31. {
  32. void *retval = NULL;
  33. + size = (size + 3) & ~3;
  34. #ifdef USE_ROCKBOX_ALLOC
  35. /* 32-bit aligned */
  36. - size = (size + 3) & ~3;
  37. if (size > skin_buffer_freespace())
  38. return NULL;
  39. retval = buffer_front;
  40. buffer_front += size;
  41. #elif defined(USE_HOST_MALLOC)
  42. - struct malloc_object *obj = malloc(sizeof (struct malloc_object));
  43. - if (!obj)
  44. - return NULL;
  45. - obj->object = malloc(size);
  46. - obj->next = NULL;
  47. - if (malloced_tail == NULL)
  48. - malloced_head = malloced_tail = obj;
  49. + if (malloced_tail && size <= malloced_tail->remaining)
  50. + {
  51. + retval = malloced_tail->start;
  52. + malloced_tail->start += size;
  53. + malloced_tail->remaining -= size;
  54. + }
  55. else
  56. - malloced_tail->next = obj;
  57. - malloced_tail = obj;
  58. - retval = obj->object;
  59. + {
  60. + size_t malloc_size = MALLOC_BLOCK_SIZE;
  61. + struct malloc_object *obj;
  62. + if (size > MALLOC_FREE_SPACE)
  63. + malloc_size = size + sizeof(struct malloc_object);
  64. + obj = malloc(malloc_size);
  65. + retval = obj->buf;
  66. + obj->start = obj->buf + size;
  67. + obj->remaining = malloc_size - sizeof(struct malloc_object);
  68. + obj->next = NULL;
  69. + if (malloced_tail == NULL)
  70. + malloced_head = malloced_tail = obj;
  71. + else
  72. + malloced_tail->next = obj;
  73. + malloced_tail = obj;
  74. + }
  75. #else
  76. retval = malloc(size);
  77. #endif