diff --git a/encode/avcenc.c b/encode/avcenc.c index a41fc3f..f318d80 100644 --- a/encode/avcenc.c +++ b/encode/avcenc.c @@ -2117,7 +2117,7 @@ int main(int argc, char *argv[]) file_size = ftello(yuv_fp); frame_size = picture_width * picture_height + ((picture_width * picture_height) >> 1) ; - if ((file_size < frame_size) || ((frame_size != 0) && (file_size % frame_size))) { + if ((file_size < frame_size) || (frame_size == 0) || (file_size % frame_size)) { fclose(yuv_fp); printf("The YUV file's size is not correct\n"); return -1; diff --git a/encode/hevcencode.c b/encode/hevcencode.c index dc38ccc..b7e185b 100644 --- a/encode/hevcencode.c +++ b/encode/hevcencode.c @@ -1920,7 +1920,8 @@ static int process_cmdline(int argc, char *argv[]) else { struct stat tmp; - fstat(fileno(srcyuv_fp), &tmp); + int ret = fstat(fileno(srcyuv_fp), &tmp); + CHECK_CONDITION(ret == 0); srcyuv_frames = tmp.st_size / (frame_width * frame_height * 1.5); printf("Source YUV file %s with %llu frames\n", srcyuv_fn, srcyuv_frames); @@ -3277,6 +3278,10 @@ static int calc_PSNR(double *psnr) srcyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(srcyuv_fp), i); recyuv_ptr = mmap(0, fourM, PROT_READ, MAP_SHARED, fileno(recyuv_fp), i); if ((srcyuv_ptr == MAP_FAILED) || (recyuv_ptr == MAP_FAILED)) { + if (srcyuv_ptr) + munmap(srcyuv_ptr, fourM); + if (recyuv_ptr) + munmap(recyuv_ptr, fourM); printf("Failed to mmap YUV files\n"); return 1; } diff --git a/encode/vp9enc.c b/encode/vp9enc.c index 7da95e1..eef98a4 100644 --- a/encode/vp9enc.c +++ b/encode/vp9enc.c @@ -1541,7 +1541,7 @@ main(int argc, char *argv[]) file_size = ftello(yuv_fp); frame_size = picture_width * picture_height + ((picture_width * picture_height) >> 1) ; - if ((file_size < frame_size) || ((frame_size != 0) && (file_size % frame_size))) { + if ((file_size < frame_size) || (frame_size == 0) || (file_size % frame_size)) { fclose(yuv_fp); printf("The YUV file's size is not correct\n"); return -1;