Changeset: 26823645d447 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=26823645d447
Modified Files:
        gdk/gdk_bbp.c
        gdk/gdk_heap.c
        gdk/gdk_logger.c
        gdk/gdk_utils.c
Branch: Mar2018
Log Message:

Allocation checks.


diffs (227 lines):

diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1543,10 +1543,14 @@ BBPinit(void)
        FILE *fp = NULL;
        struct stat st;
        unsigned bbpversion;
-       str bbpdirstr = GDKfilepath(0, BATDIR, "BBP", "dir");
-       str backupbbpdirstr = GDKfilepath(0, BAKDIR, "BBP", "dir");
+       str bbpdirstr, backupbbpdirstr;
        int i;
 
+       if(!(bbpdirstr = GDKfilepath(0, BATDIR, "BBP", "dir")))
+               GDKfatal("BBPinit: GDKmalloc failed\n");
+       if(!(backupbbpdirstr = GDKfilepath(0, BAKDIR, "BBP", "dir")))
+               GDKfatal("BBPinit: GDKmalloc failed\n");
+
 #ifdef NEED_MT_LOCK_INIT
        MT_lock_init(&GDKunloadLock, "GDKunloadLock");
        ATOMIC_INIT(BBPsizeLock);
@@ -3232,11 +3236,16 @@ BBPprepare(bool subcommit)
 {
        bool start_subcommit;
        int set = 1 + subcommit;
-       str bakdirpath = GDKfilepath(0, NULL, BAKDIR, NULL);
-       str subdirpath = GDKfilepath(0, NULL, SUBDIR, NULL);
-
+       str bakdirpath, subdirpath;
        gdk_return ret = GDK_SUCCEED;
 
+       if(!(bakdirpath = GDKfilepath(0, NULL, BAKDIR, NULL)))
+               return GDK_FAIL;
+       if(!(subdirpath = GDKfilepath(0, NULL, SUBDIR, NULL))) {
+               GDKfree(bakdirpath);
+               return GDK_FAIL;
+       }
+
        /* tmLock is only used here, helds usually very shortly just
         * to protect the file counters */
        MT_lock_set(&GDKtmLock);
@@ -3374,7 +3383,8 @@ BBPbackup(BAT *b, bool subcommit)
                return GDK_SUCCEED;
        }
        /* determine location dir and physical suffix */
-       srcdir = GDKfilepath(NOFARM, BATDIR, s, NULL);
+       if (!(srcdir = GDKfilepath(NOFARM, BATDIR, s, NULL)))
+               goto fail;
        s = strrchr(srcdir, DIR_SEP);
        if (!s)
                goto fail;
@@ -3392,8 +3402,9 @@ BBPbackup(BAT *b, bool subcommit)
                goto fail;
        GDKfree(srcdir);
        return GDK_SUCCEED;
-  fail:
-       GDKfree(srcdir);
+fail:
+       if(srcdir)
+               GDKfree(srcdir);
        return GDK_FAIL;
 }
 
@@ -3414,9 +3425,14 @@ BBPsync(int cnt, bat *subcommit)
        gdk_return ret = GDK_SUCCEED;
        int bbpdirty = 0;
        int t0 = 0, t1 = 0;
-
-       str bakdir = GDKfilepath(0, NULL, subcommit ? SUBDIR : BAKDIR, NULL);
-       str deldir = GDKfilepath(0, NULL, DELDIR, NULL);
+       str bakdir, deldir;
+
+       if(!(bakdir = GDKfilepath(0, NULL, subcommit ? SUBDIR : BAKDIR, NULL)))
+               return GDK_FAIL;
+       if(!(deldir = GDKfilepath(0, NULL, DELDIR, NULL))) {
+               GDKfree(bakdir);
+               return GDK_FAIL;
+       }
 
        PERFDEBUG t0 = t1 = GDKms();
 
@@ -3549,7 +3565,10 @@ force_move(int farmid, const char *srcdi
 
                strncpy(srcpath, name, len);
                srcpath[len] = '\0';
-               dstpath = GDKfilepath(farmid, dstdir, srcpath, NULL);
+               if(!(dstpath = GDKfilepath(farmid, dstdir, srcpath, NULL))) {
+                       GDKsyserror("force_move: malloc fail\n");
+                       return GDK_FAIL;
+               }
 
                /* step 1: remove the X.new file that is going to be
                 * overridden by X */
@@ -3564,7 +3583,10 @@ force_move(int farmid, const char *srcdi
 
                /* step 2: now remove the .kill file. This one is
                 * crucial, otherwise we'll never finish recovering */
-               killfile = GDKfilepath(farmid, srcdir, name, NULL);
+               if(!(killfile = GDKfilepath(farmid, srcdir, name, NULL))) {
+                       GDKsyserror("force_move: malloc fail\n");
+                       return GDK_FAIL;
+               }
                if (remove(killfile) != 0) {
                        ret = GDK_FAIL;
                        GDKsyserror("force_move: remove(%s)\n", killfile);
@@ -3580,8 +3602,12 @@ force_move(int farmid, const char *srcdi
 
                /* two legal possible causes: file exists or dir
                 * doesn't exist */
-               dstpath = GDKfilepath(farmid, dstdir, name, NULL);
-               srcpath = GDKfilepath(farmid, srcdir, name, NULL);
+               if(!(dstpath = GDKfilepath(farmid, dstdir, name, NULL)))
+                       return GDK_FAIL;
+               if(!(srcpath = GDKfilepath(farmid, srcdir, name, NULL))) {
+                       GDKfree(dstpath);
+                       return GDK_FAIL;
+               }
                if (remove(dstpath) != 0)       /* clear destination */
                        ret = GDK_FAIL;
                IODEBUG fprintf(stderr, "#remove %s = %d\n", dstpath, (int) 
ret);
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -120,7 +120,10 @@ HEAPalloc(Heap *h, size_t nitems, size_t
                char *nme;
                struct stat st;
 
-               nme = GDKfilepath(h->farmid, BATDIR, h->filename, NULL);
+               if(!(nme = GDKfilepath(h->farmid, BATDIR, h->filename, NULL))) {
+                       GDKerror("HEAPalloc: malloc failure");
+                       return GDK_FAIL;
+               }
                if (stat(nme, &st) < 0) {
                        h->storage = STORE_MMAP;
                        h->base = HEAPcreatefile(NOFARM, &h->size, nme);
@@ -336,7 +339,8 @@ HEAPshrink(Heap *h, size_t size)
                        /* don't grow */
                        return GDK_SUCCEED;
                }
-               path = GDKfilepath(h->farmid, BATDIR, h->filename, NULL);
+               if(!(path = GDKfilepath(h->farmid, BATDIR, h->filename, NULL)))
+                       return GDK_FAIL;
                p = GDKmremap(path,
                              h->storage == STORE_PRIV ?
                                MMAP_COPY | MMAP_READ | MMAP_WRITE :
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1473,14 +1473,15 @@ static gdk_return
 logger_load(int debug, const char *fn, char filename[FILENAME_MAX], logger *lg)
 {
        int id = LOG_SID;
-       FILE *fp;
+       FILE *fp = NULL;
        char bak[FILENAME_MAX];
        str filenamestr = NULL;
        log_bid snapshots_bid = 0;
        bat catalog_bid, catalog_nme, dcatalog, bid;
        int farmid = BBPselectfarm(lg->dbfarm_role, 0, offheap);
 
-       filenamestr = GDKfilepath(farmid, lg->dir, LOGFILE, NULL);
+       if(!(filenamestr = GDKfilepath(farmid, lg->dir, LOGFILE, NULL)))
+               goto error;
        snprintf(filename, FILENAME_MAX, "%s", filenamestr);
        snprintf(bak, sizeof(bak), "%s.bak", filename);
        GDKfree(filenamestr);
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -417,7 +417,7 @@ MT_init(void)
 
 #define CATNAP         50      /* time to sleep in ms for catnaps */
 
-static void THRinit(void);
+static int THRinit(void);
 static void GDKlockHome(int farmid);
 
 #ifndef STATIC_CODE_ANALYSIS
@@ -481,9 +481,11 @@ GDKinit(opt *set, int setlen)
        if (mnstr_init() < 0)
                return 0;
        MT_init_posix();
-       THRinit();
+       if (THRinit() < 0)
+               return 0;
 #ifndef NATIVE_WIN32
-       BATSIGinit();
+       if (BATSIGinit() < 0)
+               return 0;
 #endif
 #ifdef WIN32
        (void) signal(SIGABRT, BATSIGabort);
@@ -883,7 +885,8 @@ GDKlockHome(int farmid)
        assert(BBPfarms[farmid].dirname != NULL);
        assert(BBPfarms[farmid].lock_file == NULL);
 
-       gdklockpath = GDKfilepath(farmid, NULL, GDKLOCK, NULL);
+       if(!(gdklockpath = GDKfilepath(farmid, NULL, GDKLOCK, NULL)))
+               GDKfatal("GDKlockHome: malloc failure\n");
 
        /*
         * Obtain the global database lock.
@@ -1399,16 +1402,22 @@ THRhighwater(void)
  * the network.  The code below should be improved to gain speed.
  */
 
-static void
+static int
 THRinit(void)
 {
        int i = 0;
 
-       THRdata[0] = (void *) file_wastream(stdout, "stdout");
-       THRdata[1] = (void *) file_rastream(stdin, "stdin");
+       if((THRdata[0] = (void *) file_wastream(stdout, "stdout")) == NULL)
+               return -1;
+       if((THRdata[1] = (void *) file_rastream(stdin, "stdin")) == NULL) {
+               close_stream(THRdata[0]);
+               THRdata[0] = NULL;
+               return -1;
+       }
        for (i = 0; i < THREADS; i++) {
                GDKthreads[i].tid = i + 1;
        }
+       return 0;
 }
 
 void
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to