]> granicus.if.org Git - libvpx/commitdiff
vp9,encoder: check pointers before member access
authorJames Zern <jzern@google.com>
Sat, 15 Sep 2018 04:36:26 +0000 (21:36 -0700)
committerJames Zern <jzern@google.com>
Sat, 15 Sep 2018 04:36:26 +0000 (21:36 -0700)
verify pointers passed to vp9_cyclic_refresh_free() and
vp9_setup_pc_tree() before attempting to free members of the structs.

based on the change in libaom:
ie41de6b5a AV1FrameSizeTests.LargeValidSizes: avoid segfault.

Change-Id: Ib81759923cb442e19f42e6edb4b61171d8799ba6

vp9/encoder/vp9_aq_cyclicrefresh.c
vp9/encoder/vp9_context_tree.c

index 66e2babcdc3a4f90318c13a17288776d0deae388..a2a742493bc1bcafbd629ede6c55659d34598d79 100644 (file)
@@ -52,9 +52,11 @@ CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols) {
 }
 
 void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr) {
-  vpx_free(cr->map);
-  vpx_free(cr->last_coded_q_map);
-  vpx_free(cr);
+  if (cr != NULL) {
+    vpx_free(cr->map);
+    vpx_free(cr->last_coded_q_map);
+    vpx_free(cr);
+  }
 }
 
 // Check if this coding block, of size bsize, should be considered for refresh
index 52a81afb58f7fd6f656b48ea4f6b1af2fa2f9f47..b74b9027cab8fe09879a38031e97eea0f27eafc2 100644 (file)
@@ -139,17 +139,22 @@ void vp9_setup_pc_tree(VP9_COMMON *cm, ThreadData *td) {
 }
 
 void vp9_free_pc_tree(ThreadData *td) {
-  const int tree_nodes = 64 + 16 + 4 + 1;
   int i;
 
-  // Set up all 4x4 mode contexts
-  for (i = 0; i < 64; ++i) free_mode_context(&td->leaf_tree[i]);
+  if (td == NULL) return;
 
-  // Sets up all the leaf nodes in the tree.
-  for (i = 0; i < tree_nodes; ++i) free_tree_contexts(&td->pc_tree[i]);
+  if (td->leaf_tree != NULL) {
+    // Set up all 4x4 mode contexts
+    for (i = 0; i < 64; ++i) free_mode_context(&td->leaf_tree[i]);
+    vpx_free(td->leaf_tree);
+    td->leaf_tree = NULL;
+  }
 
-  vpx_free(td->pc_tree);
-  td->pc_tree = NULL;
-  vpx_free(td->leaf_tree);
-  td->leaf_tree = NULL;
+  if (td->pc_tree != NULL) {
+    const int tree_nodes = 64 + 16 + 4 + 1;
+    // Sets up all the leaf nodes in the tree.
+    for (i = 0; i < tree_nodes; ++i) free_tree_contexts(&td->pc_tree[i]);
+    vpx_free(td->pc_tree);
+    td->pc_tree = NULL;
+  }
 }