Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    redc767b r171ef85  
    209209}
    210210
    211 /* Return just one line. Returns NULL if something broke, an empty string
    212    on temporary "errors" (EAGAIN and friends). */
    213211static char *ipc_readline( int fd )
    214212{
    215         char buf[513], *eol;
     213        char *buf, *eol;
    216214        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, sizeof( buf ) - 1, MSG_PEEK );
     223        size = recv( fd, buf, 512, MSG_PEEK );
    224224        if( size == 0 || ( size < 0 && !sockerr_again() ) )
    225225                return NULL;
     
    229229                buf[size] = 0;
    230230       
    231         if( ( eol = strstr( buf, "\r\n" ) ) == NULL )
     231        eol = strstr( buf, "\r\n" );
     232        if( eol == NULL )
    232233                return NULL;
    233234        else
    234235                size = eol - buf + 2;
     236       
     237        g_free( buf );
     238        buf = g_new0( char, size + 1 );
    235239       
    236240        if( recv( fd, buf, size, 0 ) != size )
    237241                return NULL;
    238242        else
    239                 return g_strndup( buf, size - 2 );
     243                buf[size-2] = 0;
     244       
     245        return buf;
    240246}
    241247
     
    248254                cmd = irc_parse_line( buf );
    249255                if( cmd )
    250                 {
    251256                        ipc_command_exec( data, cmd, ipc_master_commands );
    252                         g_free( cmd );
    253                 }
    254                 g_free( buf );
    255257        }
    256258        else
     
    270272                cmd = irc_parse_line( buf );
    271273                if( cmd )
    272                 {
    273274                        ipc_command_exec( data, cmd, ipc_child_commands );
    274                         g_free( cmd );
    275                 }
    276                 g_free( buf );
    277275        }
    278276        else
Note: See TracChangeset for help on using the changeset viewer.