From 8aa002b25e51f2c7eb2e93b1da58da7dd377d0a2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 28 Jun 2007 01:12:16 +0000 Subject: [PATCH] * fix memory leak when adding torrents. * zero out tr_torrentParse()'s tr_info_t before filling it --- libtransmission/torrent.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 9f53da0c0..d8cad0dac 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -287,11 +287,15 @@ tr_torrentParse( const tr_handle_t * h, if( setme_info == NULL ) setme_info = &tmp; + memset( setme_info, 0, sizeof( tr_info_t ) ); ret = tr_metainfoParseFile( setme_info, h->tag, path, FALSE ); if( ret == TR_OK ) ret = infoCanAdd( h, destination, setme_info ); + if( setme_info == &tmp ) + tr_metainfoFree( &tmp ); + return ret; } @@ -329,11 +333,15 @@ tr_torrentParseHash( const tr_handle_t * h, if( setme_info == NULL ) setme_info = &tmp; + memset( setme_info, 0, sizeof( tr_info_t ) ); ret = tr_metainfoParseHash( setme_info, h->tag, hashStr ); if( ret == TR_OK ) ret = infoCanAdd( h, destination, setme_info ); + if( setme_info == &tmp ) + tr_metainfoFree( &tmp ); + return ret; } @@ -373,11 +381,15 @@ tr_torrentParseData( const tr_handle_t * h, if( setme_info == NULL ) setme_info = &tmp; + memset( setme_info, 0, sizeof( tr_info_t ) ); ret = tr_metainfoParseData( setme_info, h->tag, data, size, FALSE ); if( ret == TR_OK ) ret = infoCanAdd( h, destination, setme_info ); + if( setme_info == &tmp ) + tr_metainfoFree( &tmp ); + return ret; }