]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/file.c
avfilter/vf_identity: fix typo
[ffmpeg] / libavutil / file.c
index d946085b280dfc9328a5aaa780b35e0175b6705d..f228b723ec717b193dae758a53ddffc980417d98 100644 (file)
@@ -60,6 +60,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
     off_t off_size;
     char errbuf[128];
     *bufptr = NULL;
+    *size = 0;
 
     if (fd < 0) {
         err = AVERROR(errno);
@@ -97,6 +98,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
         av_strerror(err, errbuf, sizeof(errbuf));
         av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);
         close(fd);
+        *size = 0;
         return err;
     }
     *bufptr = ptr;
@@ -108,6 +110,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
         if (!mh) {
             av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in CreateFileMapping()\n");
             close(fd);
+            *size = 0;
             return -1;
         }
 
@@ -116,6 +119,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
         if (!ptr) {
             av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n");
             close(fd);
+            *size = 0;
             return -1;
         }
 
@@ -126,6 +130,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
     if (!*bufptr) {
         av_log(&file_log_ctx, AV_LOG_ERROR, "Memory allocation error occurred\n");
         close(fd);
+        *size = 0;
         return AVERROR(ENOMEM);
     }
     read(fd, *bufptr, *size);
@@ -138,7 +143,7 @@ out:
 
 void av_file_unmap(uint8_t *bufptr, size_t size)
 {
-    if (!size)
+    if (!size || !bufptr)
         return;
 #if HAVE_MMAP
     munmap(bufptr, size);