diff options
author | Dave Wallace <dwallacelf@gmail.com> | 2017-11-07 13:07:44 -0500 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2017-11-07 23:25:16 +0000 |
commit | e7fa24e574bd2ee36b21848bb0981eb8b3d2f96f (patch) | |
tree | c0c12cb761e5910c994892373bbe694563b2806b /src/vcl | |
parent | efcd1e9e1d7dda4e4ea3db5750925cd8f6894f4d (diff) |
VCL: Fix error handling during heap alloc
Change-Id: Ia8ab2b8677296f3d7d4a33e1faee494926e3b509
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Diffstat (limited to 'src/vcl')
-rw-r--r-- | src/vcl/vppcom.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c index 02a6b95a5ee..d8d7069438a 100644 --- a/src/vcl/vppcom.c +++ b/src/vcl/vppcom.c @@ -1448,25 +1448,36 @@ defaulted: fclose (fp); if (argv != NULL) free (argv); + vcl_mem = mmap (0, vcl_cfg->heapsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); - if (vcl_mem < 0) - clib_unix_error ("[%d] ERROR: mmap(0, %lld == 0x%llx, " - "PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, " - "-1, 0) failed!", - getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize); - + if (vcl_mem <= 0) + { + clib_unix_error ("[%d] ERROR: mmap(0, %lld == 0x%llx, " + "PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, " + "-1, 0) failed!", + getpid (), vcl_cfg->heapsize, vcl_cfg->heapsize); + return; + } heap = clib_mem_init (vcl_mem, vcl_cfg->heapsize); if (!heap) - clib_warning ("[%d] ERROR: clib_mem_init() failed!", getpid ()); - else if (VPPCOM_DEBUG > 0) { - clib_warning ("[%d] allocated VCL heap = %p, size %lld (0x%llx)", - getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize); - - vcm = clib_mem_alloc (sizeof (_vppcom_main)); - clib_memcpy (vcm, &_vppcom_main, sizeof (_vppcom_main)); + clib_warning ("[%d] ERROR: clib_mem_init() failed!", getpid ()); + return; } + vcl_mem = clib_mem_alloc (sizeof (_vppcom_main)); + if (!vcl_mem) + { + clib_warning ("[%d] ERROR: clib_mem_alloc() failed!", getpid ()); + return; + } + + clib_memcpy (vcl_mem, &_vppcom_main, sizeof (_vppcom_main)); + vcm = vcl_mem; + + if (VPPCOM_DEBUG > 0) + clib_warning ("[%d] allocated VCL heap = %p, size %lld (0x%llx)", + getpid (), heap, vcl_cfg->heapsize, vcl_cfg->heapsize); } static void |