Ignore:
Timestamp:
Jul 2, 2009, 8:20:00 PM (13 years ago)
Author:
charles
Message:

(trunk libT) #2261: Save memory by not initializing the RPC server's zlib stream until it's needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rpc-server.c

    r8767 r8773  
    7474
    7575#ifdef HAVE_ZLIB
     76    tr_bool            isStreamInitialized;
    7677    z_stream           stream;
    7778#endif
     
    327328        /* FIXME(libevent2): this won't compile under libevent2.
    328329           but we can use evbuffer_reserve_space() + evbuffer_commit_space() instead */
     330
     331        if( !server->isStreamInitialized )
     332        {
     333            server->isStreamInitialized = TRUE;
     334            server->stream.zalloc = (alloc_func) Z_NULL;
     335            server->stream.zfree = (free_func) Z_NULL;
     336            server->stream.opaque = (voidpf) Z_NULL;
     337            deflateInit( &server->stream, Z_BEST_COMPRESSION );
     338        }
    329339
    330340        server->stream.next_in = (Bytef*) content;
     
    860870        tr_free( tmp );
    861871#ifdef HAVE_ZLIB
    862     deflateEnd( &s->stream );
     872    if( s->isStreamInitialized )
     873        deflateEnd( &s->stream );
    863874#endif
    864875    tr_free( s->sessionId );
     
    933944    s->bindAddress = address.addr.addr4;
    934945
    935 #ifdef HAVE_ZLIB
    936     s->stream.zalloc = (alloc_func) Z_NULL;
    937     s->stream.zfree = (free_func) Z_NULL;
    938     s->stream.opaque = (voidpf) Z_NULL;
    939     deflateInit( &s->stream, Z_BEST_COMPRESSION );
    940 #endif
    941 
    942946    if( s->isEnabled )
    943947    {
Note: See TracChangeset for help on using the changeset viewer.