Browse code

mpool: move map allocation after error checks

David Raynor authored on 2013/10/08 02:44:19
Showing 1 changed files
... ...
@@ -452,12 +452,6 @@ struct MP *mpool_create() {
452 452
   sz = align_to_pagesize(&mp, MIN_FRAGSIZE);
453 453
   mp.u.mpm.usize = sizeof(struct MPMAP);
454 454
   mp.u.mpm.size = sz - sizeof(mp);
455
-#ifndef _WIN32
456
-  if ((mpool_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED)
457
-#else
458
-  if(!(mpool_p = (struct MP *)VirtualAlloc(NULL, sz, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)))
459
-#endif
460
-    return NULL;
461 455
   if (FRAGSBITS > 255) {
462 456
       cli_errmsg("At most 255 frags possible!\n");
463 457
       return NULL;
... ...
@@ -466,6 +460,12 @@ struct MP *mpool_create() {
466 466
       cli_errmsg("fragsz[0] too small!\n");
467 467
       return NULL;
468 468
   }
469
+#ifndef _WIN32
470
+  if ((mpool_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED)
471
+#else
472
+  if(!(mpool_p = (struct MP *)VirtualAlloc(NULL, sz, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)))
473
+#endif
474
+    return NULL;
469 475
 #ifdef CL_DEBUG
470 476
   memset(mpool_p, ALLOCPOISON, sz);
471 477
 #endif