Changeset: 3edadda6d387 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3edadda6d387
Modified Files:
        gdk/ChangeLog.Jul2021
        gdk/gdk_posix.c
Branch: Jul2021
Log Message:

Fix incorrect return after open failure in MT_mmap.


diffs (39 lines):

diff --git a/gdk/ChangeLog.Jul2021 b/gdk/ChangeLog.Jul2021
--- a/gdk/ChangeLog.Jul2021
+++ b/gdk/ChangeLog.Jul2021
@@ -1,6 +1,11 @@
 # ChangeLog file for GDK
 # This file is updated with Maddlog
 
+* Mon Feb 20 2023 Sjoerd Mullender <[email protected]>
+- If opening of a file failed when it was supposed to get memory mapped,
+  an incorrect value was returned to indicate the failure, causing
+  crashes later on.  This has been fixed.
+
 * Mon Feb 13 2023 Sjoerd Mullender <[email protected]>
 - When saving a bat failed for some reason during a low-level commit,
   this was logged in the log file, but the error was then subsequently
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -326,7 +326,7 @@ MT_mmap(const char *path, int mode, size
        fd = open(path, O_CREAT | ((mode & MMAP_WRITE) ? O_RDWR : O_RDONLY) | 
O_CLOEXEC, MONETDB_MODE);
        if (fd < 0) {
                GDKsyserror("open %s failed\n", path);
-               return MAP_FAILED;
+               return NULL;
        }
        ret = mmap(NULL,
                   len,
@@ -337,9 +337,10 @@ MT_mmap(const char *path, int mode, size
        if (ret == MAP_FAILED) {
                GDKsyserror("mmap(%s,%zu) failed\n", path, len);
                ret = NULL;
+       } else {
+               VALGRIND_MALLOCLIKE_BLOCK(ret, len, 0, 1);
        }
        close(fd);
-       VALGRIND_MALLOCLIKE_BLOCK(ret, len, 0, 1);
        return ret;
 }
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to