Ticket #4497: osm2pgsql_alloc_check.patch

File osm2pgsql_alloc_check.patch, 836 bytes (added by datendelphin, 7 years ago)

checks if the allocation of blocks was successfull, or exits nicely

  • node-ram-cache.c

    diff --git a/node-ram-cache.c b/node-ram-cache.c
    index 5a270e9..a9911e1 100644
    a b void init_node_ram_cache( int strategy, int cacheSizeMB, int fixpointscale ) { 
    367367    if ((allocStrategy & ALLOC_DENSE) > 0 ) {
    368368        fprintf(stderr, "Allocating memory for dense node cache\n");
    369369        blocks = calloc(NUM_BLOCKS,sizeof(struct ramNodeBlock));
     370        if (!blocks) {
     371            fprintf(stderr, "Unable to allocate %d MB. Try using --cache-strategy sparse\n", (NUM_BLOCKS * sizeof(struct ramNodeBlock)) / 1024);
     372            exit_nicely();
     373        }
    370374        queue = calloc( maxBlocks,sizeof(struct ramNodeBlock) );
    371375        /* Use this method of allocation if virtual memory is limited,
    372376         * or if OS allocs physical memory right away, rather than page by page