diff --git a/base/gxp1fill.c b/base/gxp1fill.c
index 6b5b43b..4941064 100644
--- a/base/gxp1fill.c
+++ b/base/gxp1fill.c
@@ -518,7 +518,7 @@ gx_dc_pure_masked_fill_rect(const gx_device_color * pdevc,
      */
     code = tile_fill_init(&state, pdevc, dev, true);
     if (code < 0)
-        return code;
+        goto exit;
     if (state.pcdev == dev || ptile->is_simple)
         code = (*gx_dc_type_data_pure.fill_rectangle)
             (pdevc, x, y, w, h, state.pcdev, lop, source);
@@ -529,6 +529,7 @@ gx_dc_pure_masked_fill_rect(const gx_device_color * pdevc,
         code = tile_by_steps(&state, x, y, w, h, ptile, &ptile->tmask,
                              tile_masked_fill);
     }
+exit:
     if (CLIPDEV_INSTALLED) {
         tile_clip_free((gx_device_tile_clip *)state.cdev);
         state.cdev = NULL;
@@ -552,7 +553,7 @@ gx_dc_devn_masked_fill_rect(const gx_device_color * pdevc,
      */
     code = tile_fill_init(&state, pdevc, dev, true);
     if (code < 0)
-        return code;
+        goto exit;
     if (state.pcdev == dev || ptile->is_simple) {
         gx_device_color dcolor = *pdevc;
 
@@ -574,6 +575,7 @@ gx_dc_devn_masked_fill_rect(const gx_device_color * pdevc,
         code = tile_by_steps(&state, x, y, w, h, ptile, &ptile->tmask,
                              tile_masked_fill);
     }
+exit:
     if (CLIPDEV_INSTALLED) {
         tile_clip_free((gx_device_tile_clip *)state.cdev);
         state.cdev = NULL;
@@ -593,7 +595,7 @@ gx_dc_binary_masked_fill_rect(const gx_device_color * pdevc,
 
     code = tile_fill_init(&state, pdevc, dev, true);
     if (code < 0)
-        return code;
+        goto exit;
     if (state.pcdev == dev || ptile->is_simple)
         code = (*gx_dc_type_data_ht_binary.fill_rectangle)
             (pdevc, x, y, w, h, state.pcdev, lop, source);
@@ -604,6 +606,7 @@ gx_dc_binary_masked_fill_rect(const gx_device_color * pdevc,
         code = tile_by_steps(&state, x, y, w, h, ptile, &ptile->tmask,
                              tile_masked_fill);
     }
+exit:
     if (CLIPDEV_INSTALLED) {
         tile_clip_free((gx_device_tile_clip *)state.cdev);
         state.cdev = NULL;
@@ -623,7 +626,7 @@ gx_dc_colored_masked_fill_rect(const gx_device_color * pdevc,
 
     code = tile_fill_init(&state, pdevc, dev, true);
     if (code < 0)
-        return code;
+        goto exit;
     if (state.pcdev == dev || ptile->is_simple)
         code = (*gx_dc_type_data_ht_colored.fill_rectangle)
             (pdevc, x, y, w, h, state.pcdev, lop, source);
@@ -634,6 +637,7 @@ gx_dc_colored_masked_fill_rect(const gx_device_color * pdevc,
         code = tile_by_steps(&state, x, y, w, h, ptile, &ptile->tmask,
                              tile_masked_fill);
     }
+exit:
     if (CLIPDEV_INSTALLED) {
         tile_clip_free((gx_device_tile_clip *)state.cdev);
         state.cdev = NULL;
@@ -1397,6 +1401,15 @@ gx_trans_pattern_fill_rect(int xmin, int ymin, int xmax, int ymax,
             gx_strip_bitmap tbits;
 
             code = tile_fill_init(&state_clist_trans, pdevc, dev, false);
+            if (code < 0)
+            {
+                /* Can't use CLIPDEV_INSTALLED macro because it assumes a tile_fill_state_t structure, called 'state' */
+                if (state_clist_trans.cdev != NULL) {
+                    tile_clip_free((gx_device_tile_clip *)state_clist_trans.cdev);
+                    state_clist_trans.cdev = NULL;
+                }
+                return code;
+            }
 
             state_clist_trans.phase.x = phase.x;
             state_clist_trans.phase.y = phase.y;
