From 204243c5bd384ee46e8ae0078513fce1f5d1348d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 22 Feb 2010 01:01:59 +0000 Subject: [PATCH] (trunk libT) #2952: "When possible, use posix_memalign() instead of valloc()" -- fixed in trunk for 1.91 --- configure.ac | 2 +- libtransmission/verify.c | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 8696ff57b..da011e838 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ fi AC_HEADER_STDC AC_HEADER_TIME -AC_CHECK_FUNCS([pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strtold syslog valloc]) +AC_CHECK_FUNCS([pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strtold syslog valloc getpagesize posix_memalign]) AC_PROG_INSTALL AC_PROG_MAKE_SET ACX_PTHREAD diff --git a/libtransmission/verify.c b/libtransmission/verify.c index 74e805f18..397ae88e0 100644 --- a/libtransmission/verify.c +++ b/libtransmission/verify.c @@ -47,10 +47,6 @@ enum /* #define STOPWATCH */ -#ifndef HAVE_VALLOC - #define valloc malloc -#endif - static tr_bool verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) { @@ -65,10 +61,30 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) tr_file_index_t fileIndex = 0; tr_file_index_t prevFileIndex = !fileIndex; tr_piece_index_t pieceIndex = 0; - const int64_t buflen = 4096; - uint8_t * buffer = valloc( buflen ); const time_t begin = tr_time( ); time_t end; + int64_t buflen; + uint8_t * buffer = NULL; + const int64_t maxbuf = 16384; + +#ifdef HAVE_GETPAGESIZE + buflen = getpagesize(); + while( buflen * 2 <= maxbuf ) + buflen *= 2; +#else + buflen = maxbuf; +#endif + +#ifdef HAVE_POSIX_MEMALIGN + if( !buffer ) + posix_memalign( (void**)&buffer, getpagesize(), buflen ); +#endif +#ifdef HAVE_VALLOC + if( !buffer ) + buffer = valloc( buflen ); +#endif + if( !buffer ) + buffer = malloc( buflen ); SHA1_Init( &sha );