mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-14 21:09:55 +02:00
use WebPSafe[CM]alloc/WebPSafeFree instead of [cm]alloc/free
there's still some malloc/free in the external example This is an encoder API change because of the introduction of WebPMemoryWriterClear() for symmetry reasons. The MemoryWriter object should probably go in examples/ instead of being in the main lib, though. mux_types.h stil contain some inlined free()/malloc() that are harder to remove (we need to put them in the libwebputils lib and make sure link is ok). Left as a TODO for now. Also: WebPDecodeRGB*() function are still returning a pointer that needs to be free()'d. We should call WebPSafeFree() on these, but it means exposing the whole mechanism. TODO(later). Change-Id: Iad2c9060f7fa6040e3ba489c8b07f4caadfab77b
This commit is contained in:
@ -28,7 +28,7 @@ WebPMux* WebPNewInternal(int version) {
|
||||
if (WEBP_ABI_IS_INCOMPATIBLE(version, WEBP_MUX_ABI_VERSION)) {
|
||||
return NULL;
|
||||
} else {
|
||||
WebPMux* const mux = (WebPMux*)malloc(sizeof(WebPMux));
|
||||
WebPMux* const mux = (WebPMux*)WebPSafeMalloc(1ULL, sizeof(WebPMux));
|
||||
// If mux is NULL MuxInit is a noop.
|
||||
MuxInit(mux);
|
||||
return mux;
|
||||
@ -56,7 +56,7 @@ static void MuxRelease(WebPMux* const mux) {
|
||||
void WebPMuxDelete(WebPMux* mux) {
|
||||
// If mux is NULL MuxRelease is a noop.
|
||||
MuxRelease(mux);
|
||||
free(mux);
|
||||
WebPSafeFree(mux);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -102,7 +102,7 @@ static WebPMuxError CreateFrameFragmentData(
|
||||
assert(info->dispose_method == (info->dispose_method & 1));
|
||||
// Note: assertion on upper bounds is done in PutLE24().
|
||||
|
||||
frame_frgm_bytes = (uint8_t*)malloc(frame_frgm_size);
|
||||
frame_frgm_bytes = (uint8_t*)WebPSafeMalloc(1ULL, frame_frgm_size);
|
||||
if (frame_frgm_bytes == NULL) return WEBP_MUX_MEMORY_ERROR;
|
||||
|
||||
PutLE24(frame_frgm_bytes + 0, info->x_offset / 2);
|
||||
@ -619,7 +619,7 @@ WebPMuxError WebPMuxAssemble(WebPMux* mux, WebPData* assembled_data) {
|
||||
+ ChunkListDiskSize(mux->exif_) + ChunkListDiskSize(mux->xmp_)
|
||||
+ ChunkListDiskSize(mux->unknown_) + RIFF_HEADER_SIZE;
|
||||
|
||||
data = (uint8_t*)malloc(size);
|
||||
data = (uint8_t*)WebPSafeMalloc(1ULL, size);
|
||||
if (data == NULL) return WEBP_MUX_MEMORY_ERROR;
|
||||
|
||||
// Emit header & chunks.
|
||||
@ -636,7 +636,7 @@ WebPMuxError WebPMuxAssemble(WebPMux* mux, WebPData* assembled_data) {
|
||||
// Validate mux.
|
||||
err = MuxValidate(mux);
|
||||
if (err != WEBP_MUX_OK) {
|
||||
free(data);
|
||||
WebPSafeFree(data);
|
||||
data = NULL;
|
||||
size = 0;
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ WebPMuxError ChunkSetNth(WebPChunk* chunk, WebPChunk** chunk_list,
|
||||
return WEBP_MUX_NOT_FOUND;
|
||||
}
|
||||
|
||||
new_chunk = (WebPChunk*)malloc(sizeof(*new_chunk));
|
||||
new_chunk = (WebPChunk*)WebPSafeMalloc(1ULL, sizeof(*new_chunk));
|
||||
if (new_chunk == NULL) return WEBP_MUX_MEMORY_ERROR;
|
||||
*new_chunk = *chunk;
|
||||
chunk->owner_ = 0;
|
||||
@ -179,7 +179,7 @@ WebPMuxError ChunkSetNth(WebPChunk* chunk, WebPChunk** chunk_list,
|
||||
|
||||
WebPChunk* ChunkDelete(WebPChunk* const chunk) {
|
||||
WebPChunk* const next = ChunkRelease(chunk);
|
||||
free(chunk);
|
||||
WebPSafeFree(chunk);
|
||||
return next;
|
||||
}
|
||||
|
||||
@ -312,7 +312,7 @@ WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list) {
|
||||
wpi_list = &cur_wpi->next_;
|
||||
}
|
||||
|
||||
new_wpi = (WebPMuxImage*)malloc(sizeof(*new_wpi));
|
||||
new_wpi = (WebPMuxImage*)WebPSafeMalloc(1ULL, sizeof(*new_wpi));
|
||||
if (new_wpi == NULL) return WEBP_MUX_MEMORY_ERROR;
|
||||
*new_wpi = *wpi;
|
||||
new_wpi->next_ = NULL;
|
||||
@ -331,7 +331,7 @@ WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list) {
|
||||
WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi) {
|
||||
// Delete the components of wpi. If wpi is NULL this is a noop.
|
||||
WebPMuxImage* const next = MuxImageRelease(wpi);
|
||||
free(wpi);
|
||||
WebPSafeFree(wpi);
|
||||
return next;
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
|
||||
data += RIFF_HEADER_SIZE;
|
||||
size -= RIFF_HEADER_SIZE;
|
||||
|
||||
wpi = (WebPMuxImage*)malloc(sizeof(*wpi));
|
||||
wpi = (WebPMuxImage*)WebPSafeMalloc(1ULL, sizeof(*wpi));
|
||||
if (wpi == NULL) goto Err;
|
||||
MuxImageInit(wpi);
|
||||
|
||||
@ -375,7 +375,7 @@ static WebPMuxError SynthesizeBitstream(const WebPMuxImage* const wpi,
|
||||
// Note: No need to output ANMF/FRGM chunk for a single image.
|
||||
const size_t size = RIFF_HEADER_SIZE + vp8x_size + alpha_size +
|
||||
ChunkDiskSize(wpi->img_);
|
||||
uint8_t* const data = (uint8_t*)malloc(size);
|
||||
uint8_t* const data = (uint8_t*)WebPSafeMalloc(1ULL, size);
|
||||
if (data == NULL) return WEBP_MUX_MEMORY_ERROR;
|
||||
|
||||
// Main RIFF header.
|
||||
|
Reference in New Issue
Block a user