Bug 801571 - Override vasprintf and asprint for Android platform to avoid the mismatch of malloc()/free(). r=glandium

DONTBUILD
This commit is contained in:
Shelly Lin 2014-01-17 16:54:06 +08:00
parent 913aa4dc43
commit 5a3b503309
3 changed files with 55 additions and 0 deletions

View File

@ -7074,6 +7074,7 @@ if test -n "$_WRAP_MALLOC"; then
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=malloc,--wrap=calloc,--wrap=valloc,--wrap=free,--wrap=realloc,--wrap=memalign"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=__builtin_new,--wrap=__builtin_vec_new,--wrap=__builtin_delete,--wrap=__builtin_vec_delete"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=strdup,--wrap=strndup"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=vasprintf,--wrap=asprintf"
WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=posix_memalign,--wrap=malloc_usable_size"
dnl Wrap operator new and operator delete on Android.
if test "$OS_TARGET" = "Android"; then

View File

@ -88,6 +88,51 @@ strdup_impl(const char *src)
}
#endif /* XP_DARWIN */
#ifdef ANDROID
#include <stdarg.h>
MOZ_MEMORY_API int
vasprintf_impl(char **str, const char *fmt, va_list ap)
{
if (str == NULL || fmt == NULL) {
return -1;
}
char* ptr = (char*)malloc_impl(128);
if (ptr == NULL) {
return -1;
}
int ret = vsnprintf(ptr, 128, fmt, ap);
if (ret < 0) {
free_impl(ptr);
return ret;
}
char* _ptr = realloc_impl(ptr, ret + 1);
if (_ptr == NULL) {
return -1;
}
*str = _ptr;
return ret;
}
MOZ_MEMORY_API int
asprintf_impl(char **str, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
int ret = vasprintf_impl(str, fmt, ap);
va_end(ap);
return ret;
}
#endif
#ifdef XP_WIN
/*
* There's a fun allocator mismatch in (at least) the VS 2010 CRT

View File

@ -212,6 +212,15 @@
# define wcsdup_impl mozmem_dup_impl(wcsdup)
#endif
/* String functions */
#ifdef ANDROID
/* Bug 801571 and Bug 879668, libstagefright uses vasprintf, causing malloc()/
* free() to be mismatched between bionic and mozglue implementation.
*/
#define vasprintf_impl mozmem_dup_impl(vasprintf)
#define asprintf_impl mozmem_dup_impl(asprintf)
#endif
/* Jemalloc specific function */
#define jemalloc_stats_impl mozmem_jemalloc_impl(jemalloc_stats)
#define jemalloc_purge_freed_pages_impl mozmem_jemalloc_impl(jemalloc_purge_freed_pages)