Changeset 178e2f8 for ipc.c


Ignore:
Timestamp:
2008-06-28T17:32:41Z (11 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
47b571d
Parents:
2e0f24d (diff), e0f9170 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ipc.c

    r2e0f24d r178e2f8  
    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
     
    254248                cmd = irc_parse_line( buf );
    255249                if( cmd )
     250                {
    256251                        ipc_command_exec( data, cmd, ipc_master_commands );
     252                        g_free( cmd );
     253                }
     254                g_free( buf );
    257255        }
    258256        else
     
    272270                cmd = irc_parse_line( buf );
    273271                if( cmd )
     272                {
    274273                        ipc_command_exec( data, cmd, ipc_child_commands );
     274                        g_free( cmd );
     275                }
     276                g_free( buf );
    275277        }
    276278        else
Note: See TracChangeset for help on using the changeset viewer.