]> granicus.if.org Git - transmission/commitdiff
(trunk libT) heap pruning: using the same mechanism as in r12388, avoid an unnecessar...
authorJordan Lee <jordan@transmissionbt.com>
Wed, 27 Apr 2011 21:33:52 +0000 (21:33 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Wed, 27 Apr 2011 21:33:52 +0000 (21:33 +0000)
libtransmission/bencode.c

index 10093846bd1b58e28e84211843f42023e4f9d7e2..45ad90ff65e626f4fb538d596c8082c3d7c3580e 100644 (file)
@@ -1683,8 +1683,10 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
 
         /* save the benc to a temporary file */
         {
-            char * buf = tr_bencToStr( top, mode, &nleft );
-            const char * walk = buf;
+            struct evbuffer * buf = tr_bencToBuf( top, mode );
+            const char * walk = (const char *) evbuffer_pullup( buf, -1 );
+            nleft = evbuffer_get_length( buf );
+
             while( nleft > 0 ) {
                 const int n = write( fd, walk, nleft );
                 if( n >= 0 ) {
@@ -1696,7 +1698,8 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
                     break;
                 }
             }
-            tr_free( buf );
+
+            evbuffer_free( buf );
         }
 
         if( nleft > 0 )