Properly check for mmap failure

This commit is contained in:
graindcafe 2021-12-27 12:06:13 +01:00
parent e35fa50e48
commit d46323883c

View file

@ -75,7 +75,7 @@ int quirc_resize(struct quirc *q, int w, int h)
* mmap will ensure memory page alignment * mmap will ensure memory page alignment
*/ */
image = mmap(NULL, newdim, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); image = mmap(NULL, newdim, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (!image) if (image == MAP_FAILED)
goto fail; goto fail;
memset(image, 0, newdim); memset(image, 0, newdim);
@ -136,7 +136,7 @@ int quirc_resize(struct quirc *q, int w, int h)
return 0; return 0;
/* NOTREACHED */ /* NOTREACHED */
fail: fail:
if (image != NULL) if (image != NULL && image != MAP_FAILED)
munmap(image, newdim); munmap(image, newdim);
free(pixels); free(pixels);
free(vars); free(vars);