Ignore:
Timestamp:
Jun 19, 2007, 1:49:56 AM (15 years ago)
Author:
charles
Message:
  • makemeta: don't add dotfiles to the torrents
  • bencode: trying to chase down a memory leak
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.c

    r2024 r2162  
    3030static int makeroom( benc_val_t * val, int count )
    3131{
    32     int    len;
    33     void * new;
    34 
    3532    assert( TYPE_LIST == val->type || TYPE_DICT == val->type );
    3633
    37     if( val->val.l.count + count <= val->val.l.alloc )
    38     {
    39         return 0;
    40     }
    41 
    42     /* We need a bigger boat */
    43     len = val->val.l.alloc + count +
    44         ( count % LIST_SIZE ? LIST_SIZE - ( count % LIST_SIZE ) : 0 );
    45     new = realloc( val->val.l.vals, len * sizeof( benc_val_t ) );
    46     if( NULL == new )
    47     {
    48         return 1;
    49     }
    50 
    51     val->val.l.alloc = len;
    52     val->val.l.vals  = new;
     34    if( val->val.l.count + count > val->val.l.alloc )
     35    {
     36        /* We need a bigger boat */
     37        const int len = val->val.l.alloc + count +
     38            ( count % LIST_SIZE ? LIST_SIZE - ( count % LIST_SIZE ) : 0 );
     39        void * new = realloc( val->val.l.vals, len * sizeof( benc_val_t ) );
     40        if( NULL == new )
     41            return 1;
     42
     43        val->val.l.alloc = len;
     44        val->val.l.vals  = new;
     45    }
    5346
    5447    return 0;
     
    328321int tr_bencInitStrDup( benc_val_t * val, const char * str )
    329322{
    330     char * new = NULL;
    331 
    332     if( NULL != str )
    333     {
    334         new = strdup( str );
    335         if( NULL == new )
    336         {
    337             return 1;
    338         }
    339     }
    340 
    341     _tr_bencInitStr( val, new, 0, 0 );
    342 
     323    char * newStr = tr_strdup( str );
     324    if( newStr == NULL )
     325        return 1;
     326
     327    _tr_bencInitStr( val, newStr, 0, 0 );
    343328    return 0;
    344329}
     
    354339    assert( TYPE_LIST == val->type );
    355340
    356     if( makeroom( val, count ) )
    357     {
    358         return 1;
    359     }
    360 
    361     return 0;
     341    return makeroom( val, count );
    362342}
    363343
     
    366346    assert( TYPE_DICT == val->type );
    367347
    368     if( makeroom( val, count * 2 ) )
    369     {
    370         return 1;
    371     }
    372 
    373     return 0;
     348    return makeroom( val, count * 2 );
    374349}
    375350
Note: See TracChangeset for help on using the changeset viewer.