bug-guile-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-guile-ncurses] [PATCH 2/2] Do not allow menu's internal data to


From: John Darrington
Subject: Re: [Bug-guile-ncurses] [PATCH 2/2] Do not allow menu's internal data to be destroyed, until the menu itself is destroyed.
Date: Tue, 3 May 2016 13:34:41 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

The error fixed here, is that the "items" pointer was getting unprotected 
whenever the 
list passed to "new-menu" went out of scope.  If this happened, any further use 
of the
menu was likely to crash.

This patch fixes the problem by making "items" owned by the menu instead of by 
the list
which was used in its creation.

On Tue, May 03, 2016 at 01:30:07PM +0200, John Darrington wrote:
     * ncurses/menu_type.c, ncurses/menu_type.h: Remove guards for items 
container and have the
       memory owned by the menu itself, instead of the list used in its 
creation.
     ---
      ncurses/menu_type.c | 16 +++++++---------
      ncurses/menu_type.h |  3 +--
      2 files changed, 8 insertions(+), 11 deletions(-)
     
     diff --git a/ncurses/menu_type.c b/ncurses/menu_type.c
     index 712cd35..277891f 100644
     --- a/ncurses/menu_type.c
     +++ b/ncurses/menu_type.c
     @@ -259,7 +259,6 @@ mark_menu (SCM x)
        scm_assert_smob_type (menu_tag, x);
      
        gm = (struct gucu_menu *) SCM_SMOB_DATA (x);
     -  scm_gc_mark (gm->items_guard);
        scm_gc_mark (gm->win_guard);
      
        return (gm->subwin_guard);
     @@ -272,11 +271,15 @@ gc_free_menu (SCM x)
      {
        struct gucu_menu *gm;
        int retval;
     +  ITEM **items;
      
        scm_assert_smob_type (menu_tag, x);
      
        gm = (struct gucu_menu *) SCM_SMOB_DATA (x);
      
     +  items = SCM_SMOB_DATA_2 (x);
     +  free (items);
     +
        assert (gm != NULL);
      
        retval = free_menu (gm->menu);
     @@ -304,8 +307,6 @@ gc_free_menu (SCM x)
          }
      
        /* Release scheme objects from the guardians */
     -  while (scm_is_true (scm_call_0 (gm->items_guard)))
     -    ;
        while (scm_is_true (scm_call_0 (gm->win_guard)))
          ;
        while (scm_is_true (scm_call_0 (gm->subwin_guard)))
     @@ -372,13 +373,15 @@ gucu_new_menu (SCM items)
        // Step 1: allocate memory
        gm = scm_gc_malloc (sizeof (struct gucu_menu), "gucu_menu");
      
     -  c_items = scm_gc_malloc (sizeof (ITEM *) * (len + 1), "gucu_menu");
     +  c_items = calloc (len + 1, sizeof (ITEM *));
      
        // Step 2: initialize it with C code
      
        // Step 3: create the smob
        SCM_NEWSMOB (smob, menu_tag, gm);
      
     +  SCM_SET_SMOB_DATA_2 (smob, c_items);
     +
        // Step 4: finish the initialization
        for (i = 0; i < len; i++)
          {
     @@ -411,18 +414,13 @@ gucu_new_menu (SCM items)
        scm_remember_upto_here_1 (items);
      
      #ifndef GUILE_1_POINT_6
     -  gm->items_guard = scm_make_guardian ();
        gm->win_guard = scm_make_guardian ();
        gm->subwin_guard = scm_make_guardian ();
      #else
     -  gm->items_guard = scm_make_guardian (SCM_BOOL_F);
        gm->win_guard = scm_make_guardian (SCM_BOOL_F);
        gm->subwin_guard = scm_make_guardian (SCM_BOOL_F);
      #endif
      
     -  /* Guard the items list */
     -  scm_call_1 (gm->items_guard, items);
     -
        return smob;
      }
      
     diff --git a/ncurses/menu_type.h b/ncurses/menu_type.h
     index 6a17e34..94291ed 100644
     --- a/ncurses/menu_type.h
     +++ b/ncurses/menu_type.h
     @@ -48,8 +48,7 @@ struct gucu_menu
        // Pointer to the menu
        MENU *menu;
      
     -  /* Guardians to hold the items, window, and subwindow SCM objects */
     -  SCM items_guard;
     +  /* Guardians to hold the window, and subwindow SCM objects */
        SCM win_guard;
        SCM subwin_guard;
      };
     -- 
     2.1.4

-- 
Avoid eavesdropping.  Send strong encryted email.
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]