Changeset da7b484


Ignore:
Timestamp:
2008-06-21T17:09:20Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
edc767b
Parents:
d419073
Message:

Fixed memory leaking ipc_readline().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    rd419073 rda7b484  
    209209}
    210210
     211/* Return just one line. Returns NULL if something broke, an empty string
     212   on temporary "errors" (EAGAIN and friends). */
    211213static char *ipc_readline( int fd )
    212214{
    213         char *buf, *eol;
     215        char buf[513], *eol;
    214216        int size;
    215        
    216         buf = g_new0( char, 513 );
    217217       
    218218        /* Because this is internal communication, it should be pretty safe
     
    221221           sockets and limites message length, messages should always be
    222222           complete. Saves us quite a lot of code and buffering. */
    223         size = recv( fd, buf, 512, MSG_PEEK );
     223        size = recv( fd, buf, sizeof( buf ) - 1, MSG_PEEK );
    224224        if( size == 0 || ( size < 0 && !sockerr_again() ) )
    225225                return NULL;
     
    229229                buf[size] = 0;
    230230       
    231         eol = strstr( buf, "\r\n" );
    232         if( eol == NULL )
     231        if( ( eol = strstr( buf, "\r\n" ) ) == NULL )
    233232                return NULL;
    234233        else
    235234                size = eol - buf + 2;
    236        
    237         g_free( buf );
    238         buf = g_new0( char, size + 1 );
    239235       
    240236        if( recv( fd, buf, size, 0 ) != size )
    241237                return NULL;
    242238        else
    243                 buf[size-2] = 0;
    244        
    245         return buf;
     239                return g_strndup( buf, size - 2 );
    246240}
    247241
Note: See TracChangeset for help on using the changeset viewer.