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