Add proper deallocations in the error paths to avoid potential memory leaks.
Unified · Split
| @@ -294,6 +294,7 @@ int main(int argc, char *argv[]) · 293 unmodified lines | ||
| 294 | 294 | |
| 295 | 295 | md5 = av_md5_alloc(); |
| 296 | 296 | if (!md5) { |
| 297 | + av_frame_free(&frame); | |
| 297 | 298 | fprintf(stderr, "Error allocating the MD5 context\n"); |
| 298 | 299 | return 1; |
| 299 | 300 | } |
| @@ -301,8 +302,10 @@ int main(int argc, char *argv[]) · 1 unmodified line | ||
| 301 | 302 | /* Set up the filtergraph. */ |
| 302 | 303 | err = init_filter_graph(&graph, &src, &sink); |
| 303 | 304 | if (err < 0) { |
| 305 | + av_frame_free(&frame); | |
| 306 | + av_freep(&md5); | |
| 304 | 307 | fprintf(stderr, "Unable to init filter graph:"); |
| 305 | − goto fail; | |
| 308 | + return 1; | |
| 306 | 309 | } |
| 307 | 310 | |
| 308 | 311 | /* the main filtering loop */ |
| @@ -353,6 +356,10 @@ int main(int argc, char *argv[]) · 44 unmodified lines | ||
| 353 | 356 | return 0; |
| 354 | 357 | |
| 355 | 358 | fail: |
| 359 | + avfilter_graph_free(&graph); | |
| 360 | + av_frame_free(&frame); | |
| 361 | + av_freep(&md5); | |
| 362 | + | |
| 356 | 363 | fprintf(stderr, "%s\n", av_err2str(err)); |
| 357 | 364 | return 1; |
| 358 | 365 | } |