Skip to content

Commit 225a4db

Browse files
committed
jpg2bmp: fix memory leak on error
in case the jpeg decode did fail we would never return the memory we allocated for the output buffer and thus create a memory leak.
1 parent ed74d59 commit 225a4db

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

conversions/to_bmp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414
#include <stddef.h>
1515
#include <string.h>
16+
#include <stdlib.h>
1617
#include "img_converters.h"
1718
#include "soc/efuse_reg.h"
1819
#include "esp_heap_caps.h"
@@ -135,6 +136,7 @@ bool jpg2bmp(const uint8_t *src, size_t src_len, uint8_t ** out, size_t * out_le
135136
jpeg_cfg.outbuf = output + BMP_HEADER_LEN;
136137
jpeg_cfg.outbuf_size = output_img.output_len;
137138
if(esp_jpeg_decode(&jpeg_cfg, &output_img) != ESP_OK){
139+
free(output);
138140
return false;
139141
}
140142

0 commit comments

Comments
 (0)