]> granicus.if.org Git - transmission/commitdiff
(trunk libT) eliminate a couple more unnecessary malloc() + free() pairs
authorCharles Kerr <charles@transmissionbt.com>
Tue, 30 Dec 2008 03:29:09 +0000 (03:29 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 30 Dec 2008 03:29:09 +0000 (03:29 +0000)
libtransmission/fdlimit.c
libtransmission/inout.c
libtransmission/platform.h
libtransmission/utils.c

index 2845284bbdca0cafa8625ec38898febeed8ac394..e8d023b4f3364d90e5f556376ea8132e7f2fb5e9 100644 (file)
@@ -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;
 }
index 6780e94aba6a185aff624f9297afa3b521d94d2f..1f0c55bfd5b60d57c0c26b5df79ad16d9deaa803 100644 (file)
@@ -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;
index 9fd1c2387d03ab51a5e8a1c9584371648ecfd7b1..3ab8f8b4c183e01ca0fbb1328986c54374ce49a8 100644 (file)
@@ -36,7 +36,7 @@
  #include <windows.h>
  #define MAX_PATH_LENGTH  MAX_PATH
 #else
- #define MAX_PATH_LENGTH  1024
+ #define MAX_PATH_LENGTH  2048
 #endif
 
 #define MAX_STACK_ARRAY_SIZE 7168
index 1c3aa49ca99e5d54e1899a94af312993befa10ca..d95a33e8efa67bcedff0fa097ae17f52a57c4fce 100644 (file)
@@ -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;