(trunk libT) heap pruning: using the same mechanism as in r12388, avoid an unnecessary malloc+memcpy+free in tr_bencToFile()
This commit is contained in:
parent
c9b54799e3
commit
c061390f65
|
@ -1683,8 +1683,10 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
|
||||||
|
|
||||||
/* save the benc to a temporary file */
|
/* save the benc to a temporary file */
|
||||||
{
|
{
|
||||||
char * buf = tr_bencToStr( top, mode, &nleft );
|
struct evbuffer * buf = tr_bencToBuf( top, mode );
|
||||||
const char * walk = buf;
|
const char * walk = (const char *) evbuffer_pullup( buf, -1 );
|
||||||
|
nleft = evbuffer_get_length( buf );
|
||||||
|
|
||||||
while( nleft > 0 ) {
|
while( nleft > 0 ) {
|
||||||
const int n = write( fd, walk, nleft );
|
const int n = write( fd, walk, nleft );
|
||||||
if( n >= 0 ) {
|
if( n >= 0 ) {
|
||||||
|
@ -1696,7 +1698,8 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tr_free( buf );
|
|
||||||
|
evbuffer_free( buf );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( nleft > 0 )
|
if( nleft > 0 )
|
||||||
|
|
Loading…
Reference in New Issue