mirror of
https://github.com/webmproject/libwebp.git
synced 2025-04-24 09:46:46 +02:00
add some checks on error paths
malloc failure could lead to free'ing non-initialized pointers Change-Id: I8156aac1fce9a47825cfd0d88eb2bd8c38a630d5
This commit is contained in:
parent
ce4c713904
commit
363012497b
@ -243,9 +243,11 @@ typedef struct {
|
|||||||
|
|
||||||
// Release the data contained by 'encoded_frame'.
|
// Release the data contained by 'encoded_frame'.
|
||||||
static void FrameRelease(EncodedFrame* const encoded_frame) {
|
static void FrameRelease(EncodedFrame* const encoded_frame) {
|
||||||
WebPDataClear(&encoded_frame->sub_frame.bitstream);
|
if (encoded_frame != NULL) {
|
||||||
WebPDataClear(&encoded_frame->key_frame.bitstream);
|
WebPDataClear(&encoded_frame->sub_frame.bitstream);
|
||||||
memset(encoded_frame, 0, sizeof(*encoded_frame));
|
WebPDataClear(&encoded_frame->key_frame.bitstream);
|
||||||
|
memset(encoded_frame, 0, sizeof(*encoded_frame));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -289,6 +291,9 @@ WebPFrameCache* WebPFrameCacheNew(int width, int height,
|
|||||||
WebPFrameCache* cache = (WebPFrameCache*)malloc(sizeof(*cache));
|
WebPFrameCache* cache = (WebPFrameCache*)malloc(sizeof(*cache));
|
||||||
if (cache == NULL) return NULL;
|
if (cache == NULL) return NULL;
|
||||||
CacheReset(cache);
|
CacheReset(cache);
|
||||||
|
// sanity init, so we can call WebPFrameCacheDelete():
|
||||||
|
cache->encoded_frames = NULL;
|
||||||
|
|
||||||
cache->is_first_frame = 1;
|
cache->is_first_frame = 1;
|
||||||
|
|
||||||
// Picture buffers.
|
// Picture buffers.
|
||||||
@ -325,11 +330,13 @@ WebPFrameCache* WebPFrameCacheNew(int width, int height,
|
|||||||
|
|
||||||
void WebPFrameCacheDelete(WebPFrameCache* const cache) {
|
void WebPFrameCacheDelete(WebPFrameCache* const cache) {
|
||||||
if (cache != NULL) {
|
if (cache != NULL) {
|
||||||
size_t i;
|
if (cache->encoded_frames != NULL) {
|
||||||
for (i = 0; i < cache->size; ++i) {
|
size_t i;
|
||||||
FrameRelease(&cache->encoded_frames[i]);
|
for (i = 0; i < cache->size; ++i) {
|
||||||
|
FrameRelease(&cache->encoded_frames[i]);
|
||||||
|
}
|
||||||
|
free(cache->encoded_frames);
|
||||||
}
|
}
|
||||||
free(cache->encoded_frames);
|
|
||||||
WebPPictureFree(&cache->prev_canvas);
|
WebPPictureFree(&cache->prev_canvas);
|
||||||
WebPPictureFree(&cache->curr_canvas);
|
WebPPictureFree(&cache->curr_canvas);
|
||||||
free(cache);
|
free(cache);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user