From 4023ed9da06a48dc97de2c11ca8347461538b54f Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Mon, 14 Jul 2025 14:10:56 +0100 Subject: [PATCH] tiles: Remove TiJoinFree() now that TiJoin[XY]1() exists and all use-cases utilize --- tiles/tile.c | 63 ++++------------------------------------------------ 1 file changed, 4 insertions(+), 59 deletions(-) diff --git a/tiles/tile.c b/tiles/tile.c index 7ea2f172..fae08668 100644 --- a/tiles/tile.c +++ b/tiles/tile.c @@ -493,63 +493,6 @@ TiSplitY_Bottom( return (newtile); } -/* Obnoxious global variable introduced to fix a use-after-free issue - * in DBMergeNMTiles0(); should get cleaned up when the one-delayed-free - * method gets purged from the code. - */ - -static Tile *tile_join_TiFree = NULL; - -/* - * -------------------------------------------------------------------- - * TiJoinFreeFinal -- - * - * Manages use-after free style bugs relating to the use of TiJoin{X,Y} - * - * Results: None - * - * Side effects: Calls TiFree() and may modify the global variable - * tile_join_TiFree. - * - * -------------------------------------------------------------------- - */ - -static void -TiJoinFreeFinal(void) -{ - Tile *tile = tile_join_TiFree; - if (tile) - { - tile_join_TiFree = NULL; - TiFree(tile); - } -} - -/* - * -------------------------------------------------------------------- - * TiJoinFree -- - * - * Tile deallocation function to use with TiJoinX() and TiJoinY(), - * running TiJoinFreeFinal() and using the global variable - * tile_join_TiFree to avoid issues with the one-delayed-free - * method. It's a bit of a hack, but it solves the problem. - * - * Results: None - * - * Side effects: Sets global variable tile_join_TiFree to point to - * the freed tile so that it won't get accidentally used before - * it is reallocated. - * - * -------------------------------------------------------------------- - */ - -static void -TiJoinFree(Tile* tile) -{ - TiJoinFreeFinal(); - tile_join_TiFree = tile; -} - /* * -------------------------------------------------------------------- * @@ -557,6 +500,8 @@ TiJoinFree(Tile* tile) * * Given two tiles sharing an entire common vertical edge, replace * them with a single tile occupying the union of their areas. + * Caller is expected to TiFree(tile2) upon return. + * See TiJoinX1() to managing delayed TiFree(). * * Results: * None. @@ -632,7 +577,6 @@ TiJoinX( if (PlaneGetHint(plane) == tile2) PlaneSetHint(plane, tile1); - TiJoinFree(tile2); } /* @@ -642,6 +586,8 @@ TiJoinX( * * Given two tiles sharing an entire common horizontal edge, replace * them with a single tile occupying the union of their areas. + * Caller is expected to TiFree(tile2) upon return. + * See TiJoinY1() to managing delayed TiFree(). * * Results: * None. @@ -717,7 +663,6 @@ TiJoinY( if (PlaneGetHint(plane) == tile2) PlaneSetHint(plane, tile1); - TiJoinFree(tile2); } #ifdef HAVE_SYS_MMAN_H