From 43219f3f6343bac0c4053835180a285a6bcee88c Mon Sep 17 00:00:00 2001 From: alex85k Date: Tue, 12 Aug 2014 16:56:36 +0600 Subject: [PATCH] Fix memory errors After https://github.com/openstreetmap/osm2pgsql/commit/d1b6c5e563e8eb9d836d97fad094f0a1b35f92ea#diff-a4a10b448709d2cc5dc0c85fb36a2b1c the RAM cache size can be zero, but ``am_cache_nodes_set_sparse`` often accesses ``sparseBlock[0]``. It gives serious memory access erros and failures during testing (detected with Intel Inspector XE when fixing Windows builds https://github.com/openstreetmap/osm2pgsql/issues/17 ). I am not sure the proposed fix is the best solution, but something should be done with this error. --- node-ram-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node-ram-cache.c b/node-ram-cache.c index 496fc1779..d2377601d 100644 --- a/node-ram-cache.c +++ b/node-ram-cache.c @@ -356,7 +356,7 @@ void init_node_ram_cache( int strategy, int cacheSizeMB, int fixpointscale ) { cacheSize = (int64_t)cacheSizeMB*(1024*1024); /* How much we can fit, and make sure it's odd */ maxBlocks = (cacheSize/(PER_BLOCK*sizeof(struct ramNode))); - maxSparseTuples = (cacheSize/sizeof(struct ramNodeID)); + maxSparseTuples = (cacheSize/sizeof(struct ramNodeID))+1; allocStrategy = strategy; scale = fixpointscale;