From: Charles Kerr Date: Tue, 30 Dec 2008 03:29:09 +0000 (+0000) Subject: (trunk libT) eliminate a couple more unnecessary malloc() + free() pairs X-Git-Tag: 1.60~633 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d463cdb5096c8b73400ee956ff90c1be43d78360;p=transmission (trunk libT) eliminate a couple more unnecessary malloc() + free() pairs --- diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 2845284bb..e8d023b4f 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -261,17 +261,16 @@ tr_fdFileCheckout( const char * folder, int doPreallocate, uint64_t desiredFileSize ) { - int i, winner = -1; + int i, winner = -1; struct tr_openfile * o; - char * filename; + char filename[MAX_PATH_LENGTH]; assert( folder && *folder ); assert( torrentFile && *torrentFile ); assert( doWrite == 0 || doWrite == 1 ); - filename = tr_buildPath( folder, torrentFile, NULL ); - dbgmsg( "looking for file '%s', writable %c", filename, - doWrite ? 'y' : 'n' ); + tr_snprintf( filename, sizeof( filename ), "%s%c%s", folder, TR_PATH_DELIMITER, torrentFile ); + dbgmsg( "looking for file '%s', writable %c", filename, doWrite ? 'y' : 'n' ); tr_lockLock( gFd->lock ); @@ -361,7 +360,6 @@ tr_fdFileCheckout( const char * folder, const int err = TrOpenFile( winner, folder, torrentFile, doWrite, doPreallocate, desiredFileSize ); if( err ) { tr_lockUnlock( gFd->lock ); - tr_free( filename ); errno = err; return -1; } @@ -376,7 +374,6 @@ tr_fdFileCheckout( const char * folder, o->isCheckedOut = 1; o->closeWhenDone = 0; o->date = tr_date( ); - tr_free( filename ); tr_lockUnlock( gFd->lock ); return o->fd; } diff --git a/libtransmission/inout.c b/libtransmission/inout.c index 6780e94ab..1f0c55bfd 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -73,9 +73,7 @@ readOrWriteBytes( const tr_torrent * tor, const tr_file * file = &info->files[fileIndex]; typedef size_t ( *iofunc )( int, void *, size_t ); - iofunc func = ioMode == - TR_IO_READ ? (iofunc)read : (iofunc)write; - char * path; + iofunc func = ioMode == TR_IO_READ ? (iofunc)read : (iofunc)write; struct stat sb; int fd = -1; int err; @@ -86,9 +84,11 @@ readOrWriteBytes( const tr_torrent * tor, assert( !file->length || ( fileOffset < file->length ) ); assert( fileOffset + buflen <= file->length ); - path = tr_buildPath( tor->downloadDir, file->name, NULL ); - fileExists = !stat( path, &sb ); - tr_free( path ); + { + char path[MAX_PATH_LENGTH]; + tr_snprintf( path, sizeof( path ), "%s%c%s", tor->downloadDir, TR_PATH_DELIMITER, file->name ); + fileExists = !stat( path, &sb ); + } if( !file->length ) return 0; diff --git a/libtransmission/platform.h b/libtransmission/platform.h index 9fd1c2387..3ab8f8b4c 100644 --- a/libtransmission/platform.h +++ b/libtransmission/platform.h @@ -36,7 +36,7 @@ #include #define MAX_PATH_LENGTH MAX_PATH #else - #define MAX_PATH_LENGTH 1024 + #define MAX_PATH_LENGTH 2048 #endif #define MAX_STACK_ARRAY_SIZE 7168 diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 1c3aa49ca..d95a33e8e 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -678,8 +678,7 @@ tr_strndup( const void * in, } char* -tr_strdup_printf( const char * fmt, - ... ) +tr_strdup_printf( const char * fmt, ... ) { char * ret = NULL; struct evbuffer * buf;