vlfeat / vlfeat

An open library of computer vision algorithms

Home Page:http://vlfeat.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check return value of malloc

nh2 opened this issue · comments

Most of the code doesn't seem to check the return value of malloc() (respecively the wrapper vl_malloc()).

This results in segfault crashes when the machine is running out of memory.

In the places where malloc() is directly used instead of vl_malloc(), vlfeat already correctly checks the returned value:

vlfeat/src/mser.c

Lines 363 to 371 in 1b9075f

data = malloc(vl_pgm_get_npixels (&pim) *
vl_pgm_get_bpp (&pim)) ;
if (!data) {
err = VL_ERR_ALLOC ;
snprintf(err_msg, sizeof(err_msg),
"Could not allocate enough memory.") ;
goto done ;
}

One convenient way to do it would be to just do this check directly in vl_malloc(), to handle all usages in one go.

I opened PR #193 to address this.