Changeset 64e442a in rtems


Ignore:
Timestamp:
Feb 6, 2007, 10:57:35 PM (13 years ago)
Author:
Till Straumann <strauman@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
9a673dba
Parents:
5343588
Message:

2007-02-06 Till Straumann <strauman@…>

  • libcsupport/src/gxx_wrappers.c: fix PR#690. Supply taskvar dtor to plug memory leak. Applied patch attached to PR#690.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r5343588 r64e442a  
     12007-02-06      Till Straumann <strauman@slac.stanford.edu>
     2
     3        * libcsupport/src/gxx_wrappers.c: fix PR#690. Supply
     4        taskvar dtor to plug memory leak. Applied patch attached
     5        to PR#690.
     6
    172007-02-06      Ralf Corsépius <ralf.corsepius@rtems.org>
    28
  • cpukit/libcsupport/src/gxx_wrappers.c

    r5343588 r64e442a  
    4141 * These typedefs should match with the ones defined in the file
    4242 * gcc/gthr-rtems.h in the gcc distribution.
    43  */
    44 typedef void *__gthread_key_t;
     43 * FIXME: T.S, 2007/01/31: -> gcc/gthr-rtems.h still declares
     44 *                            void * __gthread_key_t;
     45 */
     46typedef struct __gthread_key_ {
     47        void *val;                 /* this is switched with the task      */
     48        void (*dtor)(void*);   /* this remains in place for all tasks */
     49} __gthread_key, *__gthread_key_t;
    4550typedef int   __gthread_once_t;
    4651typedef void *__gthread_mutex_t;
     
    7277   {
    7378      rtems_mode saveMode;
     79      __gthread_once_t o;
    7480      rtems_task_mode(RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &saveMode);
    75       if( *(volatile __gthread_once_t *)once == 0 )
     81      if( (o = *(volatile __gthread_once_t *)once) == 0 )
    7682      {
    7783         *(volatile __gthread_once_t *)once = 1;
    78          (*func)();
    7984      }
    8085      rtems_task_mode(saveMode, RTEMS_PREEMPT_MASK, &saveMode);
     86      if ( o == 0 )
     87         (*func)();
    8188   }
    8289   return 0;
     
    9299   */
    93100   /* Do not pull your hair, trust me this works. :-) */
    94   __gthread_key_t *new_key = ( __gthread_key_t * )malloc( sizeof( __gthread_key_t ) );
    95   *key = ( __gthread_key_t )new_key;
    96   *new_key = NULL;
     101  __gthread_key_t new_key = ( __gthread_key_t )malloc( sizeof( *new_key ) );
     102  *key = new_key;
     103  new_key->val  = NULL;
     104  new_key->dtor = dtor;
    97105
    98106#ifdef DEBUG_GXX_WRAPPERS
     
    100108#endif
    101109  /* register with RTEMS the buffer that will hold the key values */
    102   if( rtems_task_variable_add( RTEMS_SELF, (void **)new_key, NULL ) == RTEMS_SUCCESSFUL )
     110  if( rtems_task_variable_add( RTEMS_SELF, (void **)new_key, dtor ) == RTEMS_SUCCESSFUL )
    103111       return 0;
    104112  return -1;
     
    110118  printk( "gxx_wrappers: dtor key=%x, ptr=%x\n", key, ptr );
    111119#endif
    112    *(void **)key = 0;
     120   key->val = 0;
    113121   return 0;
    114122}
     
    122130  if( rtems_task_variable_delete( RTEMS_SELF, (void **)key ) == RTEMS_SUCCESSFUL )
    123131  {
     132     /* Hmm - hopefully all tasks using this key have gone away... */
    124133     if( key ) free( (void *)key );
    125134     return 0;
     
    137146  {
    138147    /* We do not have to do this, but what the heck ! */
    139      p= *( void **)key;
     148     p= key->val;
    140149  }
    141150  else
     
    144153     * threads are using at the moment of this call
    145154     */
    146     if( rtems_task_variable_add( RTEMS_SELF, (void **)key, NULL ) != RTEMS_SUCCESSFUL )
     155    if( rtems_task_variable_add( RTEMS_SELF, (void **)key, key->dtor ) != RTEMS_SUCCESSFUL )
    147156    {
    148157       rtems_panic ("rtems_gxx_getspecific");
    149158    }
    150     *( void ** )key = (void *)0;
     159    key->val = (void *)0;
    151160  }
    152161
     
    164173#endif
    165174  /* register with RTEMS the buffer that will hold the key values */
    166   if( rtems_task_variable_add( RTEMS_SELF, (void **)key, NULL ) == RTEMS_SUCCESSFUL )
     175  if( rtems_task_variable_add( RTEMS_SELF, (void **)key, key->dtor ) == RTEMS_SUCCESSFUL )
    167176  {
    168177    /* now let's set the proper value */
    169     *( void ** )key = (void *)ptr;
     178    key->val = (void *)ptr;
    170179     return 0;
    171180  }
Note: See TracChangeset for help on using the changeset viewer.