ref: 0cf63fb76a9c7ebf72de2878a628a12673ee232c
parent: 9fd4ede0ec96178bf6ca2d5b7c9ae15e0b7eee54
author: James Almer <jamrial@gmail.com>
date: Tue Sep 25 14:50:01 EDT 2018
make dav1d_close() write NULL to the Dav1dContext pointer after freeing it This prevents leaving the caller with a dangling pointer.
--- a/include/dav1d/dav1d.h
+++ b/include/dav1d/dav1d.h
@@ -80,8 +80,8 @@
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__ */
--- a/src/lib.c
+++ b/src/lib.c
@@ -209,9 +209,12 @@
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 @@
if (c->refs[n].segmap)
dav1d_ref_dec(c->refs[n].segmap);
}
- dav1d_free_aligned(c);
+ dav1d_freep_aligned(c_out);
}
--- a/tools/dav1d.c
+++ b/tools/dav1d.c
@@ -167,7 +167,7 @@
fprintf(stderr, "No data decoded\n");
res = 1;
}
- dav1d_close(c);
+ dav1d_close(&c);
return res;
}