]> granicus.if.org Git - gc/commitdiff
Fix null dereference in reclaim_block if DONT_ADD_BYTE_AT_END
authorHamayama <hamay1010@gmail.com>
Tue, 20 Jun 2017 08:56:20 +0000 (11:56 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 3 Jul 2017 07:32:48 +0000 (10:32 +0300)
(Cherry-pick commit ddde4e5 from 'release-7_6' branch.)

Issue #167 (bdwgc).

* reclaim.c (GC_reclaim_block): If ok->ok_reclaim_list is null then
do not update hhdr->hb_next (and *rlh).

reclaim.c

index f2bc8b292b8a7ef7b620b681aa0ef4387f331cf3..a08c4b1beeaf202d17911769cd039ecee87a5c87 100644 (file)
--- a/reclaim.c
+++ b/reclaim.c
@@ -439,9 +439,13 @@ STATIC void GC_reclaim_block(struct hblk *hbp, word report_if_found)
           }
         } else if (GC_find_leak || !GC_block_nearly_full(hhdr)) {
           /* group of smaller objects, enqueue the real work */
-          rlh = &(ok -> ok_reclaim_list[BYTES_TO_GRANULES(sz)]);
-          hhdr -> hb_next = *rlh;
-          *rlh = hbp;
+          rlh = ok -> ok_reclaim_list;
+
+          if (rlh != NULL) {
+            rlh += BYTES_TO_GRANULES(sz);
+            hhdr -> hb_next = *rlh;
+            *rlh = hbp;
+          }
         } /* else not worth salvaging. */
         /* We used to do the nearly_full check later, but we    */
         /* already have the right cache context here.  Also     */