From 4e8290331304dfac92c3ba2c4572573cd51cd018 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 19 Aug 2007 04:03:06 +0000 Subject: [PATCH] better fix for the leak in r2870 --- libtransmission/torrent.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 83632f5c3..497e8cf1a 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -405,7 +405,7 @@ tr_torrentParse( const tr_handle_t * h, const char * destination, tr_info_t * setme_info ) { - int ret; + int ret, doFree; tr_info_t tmp; if( setme_info == NULL ) @@ -413,11 +413,12 @@ tr_torrentParse( const tr_handle_t * h, memset( setme_info, 0, sizeof( tr_info_t ) ); ret = tr_metainfoParseFile( setme_info, h->tag, path, FALSE ); + doFree = !ret && (setme_info == &tmp); if( ret == TR_OK ) ret = infoCanAdd( h, destination, setme_info ); - if( setme_info == &tmp ) + if( doFree ) tr_metainfoFree( &tmp ); return ret; @@ -455,7 +456,7 @@ tr_torrentParseHash( const tr_handle_t * h, const char * destination, tr_info_t * setme_info ) { - int ret; + int ret, doFree; tr_info_t tmp; if( setme_info == NULL ) @@ -463,11 +464,12 @@ tr_torrentParseHash( const tr_handle_t * h, memset( setme_info, 0, sizeof( tr_info_t ) ); ret = tr_metainfoParseHash( setme_info, h->tag, hashStr ); + doFree = !ret && (setme_info == &tmp); if( ret == TR_OK ) ret = infoCanAdd( h, destination, setme_info ); - if( setme_info == &tmp ) + if( doFree ) tr_metainfoFree( &tmp ); return ret; @@ -506,7 +508,7 @@ tr_torrentParseData( const tr_handle_t * h, const char * destination, tr_info_t * setme_info ) { - int ret; + int ret, doFree; tr_info_t tmp; if( setme_info == NULL ) @@ -514,11 +516,12 @@ tr_torrentParseData( const tr_handle_t * h, memset( setme_info, 0, sizeof( tr_info_t ) ); ret = tr_metainfoParseData( setme_info, h->tag, data, size, FALSE ); + doFree = !ret && (setme_info == &tmp); if( ret == TR_OK ) ret = infoCanAdd( h, destination, setme_info ); - if( setme_info == &tmp ) + if( doFree ) tr_metainfoFree( &tmp ); return ret;