Ignore:
Timestamp:
Apr 5, 2011, 6:16:21 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) more heap pruning: avoid an unnecessary malloc() + strcmp() + free() when parsing the initial handshake string from a peer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r12228 r12322  
    600600{
    601601    uint8_t   pstrlen;
    602     uint8_t * pstr;
     602    uint8_t   pstr[20];
    603603    uint8_t   reserved[HANDSHAKE_FLAGS_LEN];
    604604    uint8_t   hash[SHA_DIGEST_LENGTH];
     
    650650
    651651    /* pstr (BitTorrent) */
    652     pstr = tr_new( uint8_t, pstrlen + 1 );
     652    assert( pstrlen == 19 );
    653653    tr_peerIoReadBytes( handshake->io, inbuf, pstr, pstrlen );
    654654    pstr[pstrlen] = '\0';
    655     if( strcmp( (char*)pstr, "BitTorrent protocol" ) )
    656     {
    657         tr_free( pstr );
     655    if( memcmp( pstr, "BitTorrent protocol", 19 ) )
    658656        return tr_handshakeDone( handshake, false );
    659     }
    660     tr_free( pstr );
    661657
    662658    /* reserved bytes */
Note: See TracChangeset for help on using the changeset viewer.