Index: configure.in =================================================================== --- configure.in (revision 128) +++ configure.in (working copy) @@ -620,7 +620,8 @@ strnicmp \ strstr \ tzset \ - uname) + uname \ + getpagesize ) dnl windows has different names for a few basic things if test "x-$ac_cv_func_getpid" != "x-yes" -a "x-$ac_cv_func__getpid" = "x-yes" ; then Index: sm/storage_pgsql.c =================================================================== --- sm/storage_pgsql.c (revision 135) +++ sm/storage_pgsql.c (revision 136) @@ -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_pgsql_realloc(void **oblocks, int len) { +static size_t _st_pgsql_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); Index: sm/storage_pgsql.c =================================================================== --- sm/storage_pgsql.c (revision 138) +++ sm/storage_pgsql.c (revision 139) @@ -71,7 +71,7 @@ } /** this is the safety check used to make sure there's always enough mem */ -#define PGSQL_SAFE(blocks, size, len) if((size) > len) len = _st_pgsql_realloc((void**)&(blocks),(size)); +#define PGSQL_SAFE(blocks, size, len) if((size) >= len) len = _st_pgsql_realloc((void**)&(blocks),(size + 1)); static void _st_pgsql_convert_filter_recursive(st_filter_t f, char **buf, int *buflen, int *nbuf) { st_filter_t scan; Index: sm/storage_pgsql.c =================================================================== --- sm/storage_pgsql.c (revision 109) +++ sm/storage_pgsql.c (revision 110) @@ -491,7 +491,7 @@ cond = _st_pgsql_convert_filter(drv, owner, filter); log_debug(ZONE, "generated filter: %s", cond); - PGSQL_SAFE(buf, strlen(type) + strlen(cond) + 20, buflen); + PGSQL_SAFE(buf, strlen(type) + strlen(cond) + 23, buflen); sprintf(buf, "DELETE FROM \"%s\" WHERE %s;", type, cond); free(cond);