fix missing free()

Change-Id: Ia09869321e00bb3fb8e92e5d91993ff583dc6cdf
This commit is contained in:
Pascal Massimino 2011-03-13 00:22:57 -08:00
parent af3e2aaa04
commit bc75213572
2 changed files with 15 additions and 3 deletions

View File

@ -311,7 +311,7 @@ void WebPInitCustomIo(VP8Io* const io) {
}
//-----------------------------------------------------------------------------
// Init/Check decoding parameters
// Init/Check/Free decoding parameters and buffer
int WebPInitDecParams(const uint8_t* data, uint32_t data_size, int* width,
int* height, WebPDecParams* const params) {
@ -376,6 +376,11 @@ int WebPCheckDecParams(const VP8Io* io, const WebPDecParams* params,
return ok;
}
void WebPClearDecParams(WebPDecParams* params) {
free(params->output);
memset(params, 0, sizeof(*params));
}
//-----------------------------------------------------------------------------
// "Into" variants
@ -510,11 +515,14 @@ static uint8_t* Decode(WEBP_CSP_MODE mode, const uint8_t* data,
if (!WebPInitDecParams(data, data_size, width, height, &params)) {
return NULL;
}
if (params_out) *params_out = params;
size = params.stride * (*height);
uv_size = params.u_stride * ((*height + 1) / 2);
return DecodeInto(mode, data, data_size, &params, size, uv_size, uv_size);
if (!DecodeInto(mode, data, data_size, &params, size, uv_size, uv_size)) {
WebPClearDecParams(&params);
}
if (params_out) *params_out = params;
return params.output;
}
uint8_t* WebPDecodeRGB(const uint8_t* data, uint32_t data_size,

View File

@ -52,6 +52,10 @@ int WebPInitDecParams(const uint8_t* data, uint32_t data_size, int* width,
int WebPCheckDecParams(const VP8Io* io, const WebPDecParams* params,
int output_size, int output_u_size, int output_v_size);
// Deallocate memory allocated by WebPInitDecParams() and reset the
// WebPDecParams object.
void WebPClearDecParams(WebPDecParams* params);
#if defined(__cplusplus) || defined(c_plusplus)
} // extern "C"
#endif