This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository terminology.

View the commit online.

commit 2e9bde32d445823e68f56c59df30e39fcc0cf2c2
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 12:50:06 2026 -0600

    termpty: release the old screen's blocks on resize
    
    A block counts one reference per cell that shows it, and the rewrap of
    a resize takes one for every cell it copies to the new screen. As with
    links, the old screen was freed without giving its own back, so each
    resize added the block's cells to its count. A block shown during a
    resize was then never freed, not even once cleared off the screen.
    
    The old screen now gives back its block references along with its link
    references.
---
 src/bin/termpty.c    | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 src/bin/tytest.c     |  1 +
 src/bin/unit_tests.h |  1 +
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index a2f8edc7..2ad39bc4 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -1532,6 +1532,20 @@ _cells_links_ref(Termpty *ty, const Termcell *cells, int n, Eina_Bool take)
      }
 }
 
+/* Give back the block and link references of n cells about to be freed. */
+static void
+_cells_refs_release(Termpty *ty, const Termcell *cells, int n)
+{
+   int i;
+
+   if (ty->block.blocks)
+     {
+        for (i = 0; i < n; i++)
+          HANDLE_BLOCK_CODEPOINT_OVERWRITE(ty, cells[i].codepoint, 0);
+     }
+   _cells_links_ref(ty, cells, n, EINA_FALSE);
+}
+
 static void
 _backlog_remove_latest_nolock(Termpty *ty)
 {
@@ -1695,7 +1709,7 @@ termpty_resize(Termpty *ty, int new_w, int new_h)
      }
 
    /* the rewrap took references for the cells it copied */
-   _cells_links_ref(ty, ty->screen, old_w * old_h, EINA_FALSE);
+   _cells_refs_release(ty, ty->screen, old_w * old_h);
    free(ty->screen);
    ty->screen = new_screen;
 
@@ -4835,4 +4849,38 @@ tytest_resize_screen_link_refs(void)
 }
 #endif
 
+#if defined(BINARY_TYTEST)
+/* A resize moves the screen's cells to a new screen: a block keeps one
+ * reference per cell that shows it, and goes once the screen is cleared. */
+int
+tytest_resize_screen_block_refs(void)
+{
+   Termblock *blk;
+   Termpty ty;
+   int id;
+
+   _ty_test_init(&ty, 10, 3);
+   blk = termpty_block_new(&ty, 1, 1, "/img.png", NULL);
+   assert(blk);
+   id = blk->id;
+   termpty_block_insert(&ty, '#', blk);
+   ty.block.on = EINA_TRUE;
+   _ty_feed(&ty, "\033[1;3H#");
+   ty.block.on = EINA_FALSE;
+   assert(blk->refs == 1);
+
+   termpty_resize(&ty, 12, 4);
+   assert(termpty_block_get(&ty, id) == blk && blk->refs == 1);
+   termpty_resize(&ty, 8, 3);
+   assert(termpty_block_get(&ty, id) == blk && blk->refs == 1);
+
+   _ty_feed(&ty, "\033[2J");
+   assert(!termpty_block_get(&ty, id));
+
+   _ty_test_shutdown(&ty);
+   eina_hash_free(ty.block.blocks);
+   return 0;
+}
+#endif
+
 #endif /* BINARY_TYFUZZ || BINARY_TYTEST */
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index daf09b54..b8613b76 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -79,6 +79,7 @@ static struct {
        { "links_reset", tytest_links_reset},
        { "resize_wrapped_link", tytest_resize_wrapped_link},
        { "resize_screen_link_refs", tytest_resize_screen_link_refs},
+       { "resize_screen_block_refs", tytest_resize_screen_block_refs},
        { "percent_decode", tytest_percent_decode},
        { "sgr_58_no_leak", tytest_sgr_58_no_leak},
        { "xmodkeys_set", tytest_xmodkeys_set},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index b7c73988..60198949 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -52,6 +52,7 @@ int tytest_osc8_no_leak(void);
 int tytest_links_reset(void);
 int tytest_resize_wrapped_link(void);
 int tytest_resize_screen_link_refs(void);
+int tytest_resize_screen_block_refs(void);
 int tytest_percent_decode(void);
 int tytest_sgr_58_no_leak(void);
 int tytest_xmodkeys_set(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to