memory-reporting.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. commit 16362f7dc755d9a2cfb8df06db74a16fcc97e495
  2. Author: Nathan Froyd <froydnj@mozilla.com>
  3. Date: Wed Mar 5 10:58:29 2014 -0500
  4. Bug 677653 - part 1 - indirect libogg memory allocations through variables
  5. diff --git a/media/libogg/include/ogg/ogg.h b/media/libogg/include/ogg/ogg.h
  6. index cea4ebe..cebe38e 100644
  7. --- include/ogg/ogg.h
  8. +++ include/ogg/ogg.h
  9. @@ -202,6 +202,10 @@ extern int ogg_page_packets(const ogg_page *og);
  10. extern void ogg_packet_clear(ogg_packet *op);
  11. +extern void ogg_set_mem_functions(ogg_malloc_function_type *malloc_func,
  12. + ogg_calloc_function_type *calloc_func,
  13. + ogg_realloc_function_type *realloc_func,
  14. + ogg_free_function_type *free_func);
  15. #ifdef __cplusplus
  16. }
  17. diff --git a/media/libogg/include/ogg/os_types.h b/media/libogg/include/ogg/os_types.h
  18. index 2c75a20..83ed732 100644
  19. --- include/ogg/os_types.h
  20. +++ include/ogg/os_types.h
  21. @@ -17,12 +17,33 @@
  22. #ifndef _OS_TYPES_H
  23. #define _OS_TYPES_H
  24. -/* make it easy on the folks that want to compile the libs with a
  25. - different malloc than stdlib */
  26. -#define _ogg_malloc malloc
  27. -#define _ogg_calloc calloc
  28. -#define _ogg_realloc realloc
  29. -#define _ogg_free free
  30. +#include <stddef.h>
  31. +
  32. +/* We indirect mallocs through settable-at-runtime functions to accommodate
  33. + memory reporting in the browser. */
  34. +
  35. +#ifdef __cplusplus
  36. +extern "C" {
  37. +#endif
  38. +
  39. +typedef void* (ogg_malloc_function_type)(size_t);
  40. +typedef void* (ogg_calloc_function_type)(size_t, size_t);
  41. +typedef void* (ogg_realloc_function_type)(void*, size_t);
  42. +typedef void (ogg_free_function_type)(void*);
  43. +
  44. +extern ogg_malloc_function_type *ogg_malloc_func;
  45. +extern ogg_calloc_function_type *ogg_calloc_func;
  46. +extern ogg_realloc_function_type *ogg_realloc_func;
  47. +extern ogg_free_function_type *ogg_free_func;
  48. +
  49. +#ifdef __cplusplus
  50. +}
  51. +#endif
  52. +
  53. +#define _ogg_malloc ogg_malloc_func
  54. +#define _ogg_calloc ogg_calloc_func
  55. +#define _ogg_realloc ogg_realloc_func
  56. +#define _ogg_free ogg_free_func
  57. #if defined(_WIN32)
  58. diff --git a/media/libogg/src/ogg_alloc.c b/media/libogg/src/ogg_alloc.c
  59. new file mode 100644
  60. index 0000000..4238d7b
  61. --- /dev/null
  62. +++ src/ogg_alloc.c
  63. @@ -0,0 +1,31 @@
  64. +/********************************************************************
  65. + * *
  66. + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  67. + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  68. + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  69. + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  70. + * *
  71. + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
  72. + * by the Xiph.Org Foundation http://www.xiph.org/ *
  73. + * *
  74. + *********************************************************************/
  75. +
  76. +#include <stdlib.h>
  77. +#include "ogg/os_types.h"
  78. +
  79. +ogg_malloc_function_type *ogg_malloc_func = malloc;
  80. +ogg_calloc_function_type *ogg_calloc_func = calloc;
  81. +ogg_realloc_function_type *ogg_realloc_func = realloc;
  82. +ogg_free_function_type *ogg_free_func = free;
  83. +
  84. +void
  85. +ogg_set_mem_functions(ogg_malloc_function_type *malloc_func,
  86. + ogg_calloc_function_type *calloc_func,
  87. + ogg_realloc_function_type *realloc_func,
  88. + ogg_free_function_type *free_func)
  89. +{
  90. + ogg_malloc_func = malloc_func;
  91. + ogg_calloc_func = calloc_func;
  92. + ogg_realloc_func = realloc_func;
  93. + ogg_free_func = free_func;
  94. +}