Changeset: 4341382521fe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4341382521fe
Modified Files:
        monetdb5/mal/mal_box.c
Branch: Jan2014
Log Message:

Close resource leak + add assertion that hopefully helps Coverity.


diffs (40 lines):

diff --git a/monetdb5/mal/mal_box.c b/monetdb5/mal/mal_box.c
--- a/monetdb5/mal/mal_box.c
+++ b/monetdb5/mal/mal_box.c
@@ -662,8 +662,11 @@ prepareSaveBox(Box box, str *boxfile, st
        *boxfile = boxFileName(box, 0);
        *boxfilebak = boxFileName(box, "backup");
 
-       if (*boxfile == 0)
+       if (*boxfile == NULL || *boxfilebak == NULL) {
+               GDKfree(*boxfile); *boxfile = NULL;
+               GDKfree(*boxfilebak); *boxfilebak = NULL;
                return 0;
+       }
        if (rename(*boxfile, *boxfilebak) < 0 && errno != ENOENT) {
 #ifdef DEBUG_MAL_BOX
                mnstr_printf(GDKout, "saveBox:can not rename %s to %s\n", 
*boxfile, *boxfilebak);
@@ -682,9 +685,8 @@ prepareSaveBox(Box box, str *boxfile, st
        if (f != NULL){
                if( chmod(*boxfile, (S_IRUSR | S_IWUSR)) )
                        showException(GDKout, MAL,"box.saveBox", "can not 
change box file mode");
-       } else
+       } else {
                showException(GDKout, MAL,"box.saveBox", "can not create box 
file");
-       if (f == NULL) {
                GDKfree(*boxfile); *boxfile= NULL;
                GDKfree(*boxfilebak); *boxfilebak= NULL;
        }
@@ -708,8 +710,11 @@ saveBox(Box box, int flag)
                return 0;
        }
        f = prepareSaveBox(box, &boxfile, &boxfilebak);
-       if (f == NULL)
+       if (f == NULL) {
+               assert(boxfile == NULL);
+               assert(boxfilebak == NULL);
                return 1;
+       }
 #ifdef DEBUG_MAL_BOX
        mnstr_printf(GDKout, "saveBox:created %s\n", boxfile);
 #endif
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to