better error control in fimg_destroy

This commit is contained in:
Tonton Th 2019-03-03 18:07:20 +01:00
parent 43b625b5ef
commit 83f80ad496
1 changed files with 9 additions and 2 deletions

View File

@ -106,7 +106,6 @@ return 0;
}
/* --------------------------------------------------------------------- */
int fimg_destroy(FloatImg *fimg)
{
@ -114,10 +113,18 @@ int fimg_destroy(FloatImg *fimg)
fprintf(stderr, ">>> %-25s ( %p )\n", __func__, fimg);
#endif
if (NULL == fimg) {
fprintf(stderr, "%s : parameter is null\n", __func__);
return -1;
}
if ( ! fimg_type_is_valid(fimg->type) ) {
return -2;
}
if (NULL == fimg->R) {
fprintf(stderr, "%s : %p already freeed\n", __func__, fimg);
return -3;
}
free(fimg->R);
memset(fimg, 0, sizeof(FloatImg));