ref: 0435ec9cef090d42768cf26daa2a7ab58dd30719
parent: 632b4876e3869aea085427cc79f5d08487d848de
author: Henrik Gramner <gramner@twoorioles.com>
date: Thu Jul 4 23:40:45 EDT 2019
Fix potential memory leak In the (very unlikely) scenario of a pthread mutex/cond init failure in the tile state reallocation code some newly allocated mutexes/conds could leak.
--- a/src/decode.c
+++ b/src/decode.c
@@ -2624,7 +2624,7 @@
Dav1dTileState *ts_new = realloc(f->ts, sizeof(*f->ts) * n_ts);
if (!ts_new) goto error;
f->ts = ts_new;
- for (int n = f->n_ts; n < n_ts; n++) {
+ for (int n = f->n_ts; n < n_ts; f->n_ts = ++n) {
Dav1dTileState *const ts = &f->ts[n];
if (pthread_mutex_init(&ts->tile_thread.lock, NULL)) goto error;
if (pthread_cond_init(&ts->tile_thread.cond, NULL)) {
@@ -2632,7 +2632,6 @@
goto error;
}
}
- f->n_ts = n_ts;
} else {
for (int n = n_ts; n < f->n_ts; n++) {
Dav1dTileState *const ts = &f->ts[n];