Index: sm/storage_mysql.c =================================================================== --- sm/storage_mysql.c (revision 139) +++ sm/storage_mysql.c (revision 140) @@ -42,15 +42,27 @@ int txn; } *drvdata_t; -#define BLOCKSIZE (1024) +#define FALLBACK_BLOCKSIZE (4096) /** internal: do and return the math and ensure it gets realloc'd */ -static int _st_mysql_realloc(void **oblocks, int len) { +static size_t _st_mysql_realloc(void **oblocks, size_t len) { void *nblocks; - int nlen; + size_t nlen; + static size_t block_size = 0; + if (block_size == 0) { +#ifdef HAVE_GETPAGESIZE + block_size = getpagesize(); +#elif defined(_SC_PAGESIZE) + block_size = sysconf(_SC_PAGESIZE); +#elif defined(_SC_PAGE_SIZE) + block_size = sysconf(_SC_PAGE_SIZE); +#else + block_size = FALLBACK_BLOCKSIZE; +#endif + } /* round up to standard block sizes */ - nlen = (((len-1)/BLOCKSIZE)+1)*BLOCKSIZE; + nlen = (((len-1)/block_size)+1)*block_size; /* keep trying till we get it */ while((nblocks = realloc(*oblocks, nlen)) == NULL) sleep(1); @@ -59,7 +71,7 @@ } /** this is the safety check used to make sure there's always enough mem */ -#define MYSQL_SAFE(blocks, size, len) if((size) > len) len = _st_mysql_realloc((void**)&(blocks),(size)); +#define MYSQL_SAFE(blocks, size, len) if((size) >= len) len = _st_mysql_realloc((void**)&(blocks),(size + 1)); static void _st_mysql_convert_filter_recursive(st_filter_t f, char **buf, int *buflen, int *nbuf) { st_filter_t scan;