Commit 0cf63fb7 authored by James Almer's avatar James Almer

make dav1d_close() write NULL to the Dav1dContext pointer after freeing it

This prevents leaving the caller with a dangling pointer.
parent 9fd4ede0
......@@ -80,8 +80,8 @@ DAV1D_API int dav1d_open(Dav1dContext **c_out, const Dav1dSettings *s);
DAV1D_API int dav1d_decode(Dav1dContext *c, Dav1dData *in, Dav1dPicture *out);
/**
* Close decoder instance, free all associated memory.
* Close decoder instance, free all associated memory, and set $c_out to NULL.
*/
DAV1D_API void dav1d_close(Dav1dContext *c);
DAV1D_API void dav1d_close(Dav1dContext **c_out);
#endif /* __DAV1D_H__ */
......@@ -209,8 +209,11 @@ int dav1d_decode(Dav1dContext *const c,
return -EAGAIN;
}
void dav1d_close(Dav1dContext *const c) {
validate_input(c != NULL);
void dav1d_close(Dav1dContext **const c_out) {
validate_input(c_out != NULL);
Dav1dContext *const c = *c_out;
if (!c) return;
for (int n = 0; n < c->n_fc; n++) {
Dav1dFrameContext *const f = &c->fc[n];
......@@ -295,5 +298,5 @@ void dav1d_close(Dav1dContext *const c) {
if (c->refs[n].segmap)
dav1d_ref_dec(c->refs[n].segmap);
}
dav1d_free_aligned(c);
dav1d_freep_aligned(c_out);
}
......@@ -167,7 +167,7 @@ int main(const int argc, char *const *const argv) {
fprintf(stderr, "No data decoded\n");
res = 1;
}
dav1d_close(c);
dav1d_close(&c);
return res;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment