| diff --git a/third_party/libopenjpeg20/opj_malloc.cc b/third_party/libopenjpeg20/opj_malloc.cc | |
| new file mode 100644 | |
| --- /dev/null | |
| +++ b/third_party/libopenjpeg20/opj_malloc.cc | |
| @@ -0,0 +1,42 @@ | |
| +// Copyright 2020 PDFium Authors. All rights reserved. | |
| +// Use of this source code is governed by a BSD-style license that can be | |
| +// found in the LICENSE file. | |
| + | |
| +// Deliberately not including opj_malloc.h, which has poisoned malloc and | |
| +// friends. | |
| + | |
| +#include "core/fxcrt/fx_memory.h" | |
| +#include "third_party/base/memory/aligned_memory.h" | |
| + | |
| +extern "C" { | |
| + | |
| +void* opj_malloc(size_t size) { | |
| + return FXMEM_DefaultAlloc(size); | |
| +} | |
| + | |
| +void* opj_calloc(size_t numOfElements, size_t sizeOfElements) { | |
| + return FXMEM_DefaultCalloc(numOfElements, sizeOfElements); | |
| +} | |
| + | |
| +void* opj_aligned_malloc(size_t size) { | |
| + return size ? pdfium::base::AlignedAlloc(size, 16) : nullptr; | |
| +} | |
| + | |
| +void opj_aligned_free(void* ptr) { | |
| + pdfium::base::AlignedFree(ptr); | |
| +} | |
| + | |
| +void* opj_aligned_32_malloc(size_t size) { | |
| + return size ? pdfium::base::AlignedAlloc(size, 32) : nullptr; | |
| +} | |
| + | |
| +void* opj_realloc(void* m, size_t s) { | |
| + return FXMEM_DefaultRealloc(m, s); | |
| +} | |
| + | |
| +void opj_free(void* m) { | |
| + if (m) | |
| + FXMEM_DefaultFree(m); | |
| +} | |
| + | |
| +} // extern "C" | |
| diff --git a/third_party/libopenjpeg20/opj_malloc.h b/third_party/libopenjpeg20/opj_malloc.h | |
| --- a/third_party/libopenjpeg20/opj_malloc.h | |
| +++ b/third_party/libopenjpeg20/opj_malloc.h | |
| @@ -33,6 +33,11 @@ | |
| #define OPJ_MALLOC_H | |
| #include <stddef.h> | |
| + | |
| +#ifdef __cplusplus | |
| +extern "C" { | |
| +#endif | |
| + | |
| /** | |
| @file opj_malloc.h | |
| @brief Internal functions | |
| @@ -68,7 +73,6 @@ Allocate memory aligned to a 16 byte bou | |
| @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available | |
| */ | |
| void * opj_aligned_malloc(size_t size); | |
| -void * opj_aligned_realloc(void *ptr, size_t size); | |
| void opj_aligned_free(void* ptr); | |
| /** | |
| @@ -77,7 +81,6 @@ Allocate memory aligned to a 32 byte bou | |
| @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available | |
| */ | |
| void * opj_aligned_32_malloc(size_t size); | |
| -void * opj_aligned_32_realloc(void *ptr, size_t size); | |
| /** | |
| Reallocate memory blocks. | |
| @@ -102,5 +105,8 @@ void opj_free(void * m); | |
| /*@}*/ | |
| -#endif /* OPJ_MALLOC_H */ | |
| +#ifdef __cplusplus | |
| +} // extern "C" | |
| +#endif | |
| +#endif /* OPJ_MALLOC_H */ |