Changeset: d3aa20a4b3bb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d3aa20a4b3bb
Modified Files:
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_upgrades.c
Branch: default
Log Message:

Memory allocation checks


diffs (96 lines):

diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -883,7 +883,7 @@ has_whitespace(const char *s)
 str
 mvc_import_table(Client cntxt, BAT ***bats, mvc *m, bstream *bs, sql_table *t, 
char *sep, char *rsep, char *ssep, char *ns, lng sz, lng offset, int locked, 
int best)
 {
-       int i = 0;
+       int i = 0, j;
        node *n;
        Tablet as;
        Column *fmt;
@@ -950,6 +950,17 @@ mvc_import_table(Client cntxt, BAT ***ba
                        fmt[i].extra = col;
                        fmt[i].len = ATOMlen(fmt[i].adt, 
ATOMnilptr(fmt[i].adt));
                        fmt[i].data = GDKzalloc(fmt[i].len);
+                       if(fmt[i].data == NULL || fmt[i].type == NULL) {
+                               for (j = 0; j < i; j++) {
+                                       GDKfree(fmt[j].type);
+                                       GDKfree(fmt[j].data);
+                                       BBPunfix(fmt[j].c->batCacheid);
+                               }
+                               GDKfree(fmt[i].type);
+                               GDKfree(fmt[i].data);
+                               sql_error(m, 500, "failed to allocate space for 
column");
+                               return NULL;
+                       }
                        fmt[i].c = NULL;
                        fmt[i].ws = !has_whitespace(fmt[i].sep);
                        fmt[i].quote = ssep ? ssep[0] : 0;
@@ -968,8 +979,17 @@ mvc_import_table(Client cntxt, BAT ***ba
 
                        if (locked) {
                                BAT *b = store_funcs.bind_col(m->session->tr, 
col, RDONLY);
-                               if (b == NULL)
+                               if (b == NULL) {
+                                       for (j = 0; j < i; j++) {
+                                               GDKfree(fmt[j].type);
+                                               GDKfree(fmt[j].data);
+                                               BBPunfix(fmt[j].c->batCacheid);
+                                       }
+                                       GDKfree(fmt[i].type);
+                                       GDKfree(fmt[i].data);
                                        sql_error(m, 500, "failed to bind to 
table column");
+                                       return NULL;
+                               }
 
                                HASHdestroy(b);
 
@@ -977,8 +997,11 @@ mvc_import_table(Client cntxt, BAT ***ba
                                cnt = BATcount(b);
                                if (sz > 0 && BATcapacity(b) < (BUN) sz) {
                                        if (BATextend(fmt[i].c, (BUN) sz) != 
GDK_SUCCEED) {
-                                               for (i--; i >= 0; i--)
-                                                       
BBPunfix(fmt[i].c->batCacheid);
+                                               for (j = 0; j <= i; j++) {
+                                                       GDKfree(fmt[j].type);
+                                                       GDKfree(fmt[j].data);
+                                                       
BBPunfix(fmt[j].c->batCacheid);
+                                               }
                                                sql_error(m, 500, "failed to 
allocate space for column");
                                                return NULL;
                                        }
@@ -992,6 +1015,7 @@ mvc_import_table(Client cntxt, BAT ***ba
                                (best || !as.error))) {
                                *bats = (BAT**) GDKzalloc(sizeof(BAT *) * 
as.nr_attrs);
                                if ( *bats == NULL){
+                                       sql_error(m, 500, "failed to allocate 
space for column");
                                        TABLETdestroy_format(&as);
                                        return NULL;
                                }
@@ -1807,6 +1831,12 @@ mvc_export_table(backend *b, stream *s, 
        as.offset = offset;
        fmt = as.format = (Column *) GDKzalloc(sizeof(Column) * (as.nr_attrs + 
1));
        tres = GDKzalloc(sizeof(struct time_res) * (as.nr_attrs));
+       if(fmt == NULL || tres == NULL) {
+               GDKfree(fmt);
+               GDKfree(tres);
+               sql_error(m, 500, "failed to allocate space");
+               return -1;
+       }
 
        fmt[0].c = NULL;
        fmt[0].sep = (csv) ? btag : "";
diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -889,7 +889,7 @@ sql_update_jul2017_sp3(Client c, mvc *sq
                size_t bufsize = 1024, pos = 0;
                char *buf = GDKmalloc(bufsize);
                if (buf == NULL)
-                       throw(SQL, "sql_update_jul2017_sp3", MAL_MALLOC_FAIL);
+                       throw(SQL, "sql_update_jul2017_sp3", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
                pos += snprintf(
                        buf + pos,
                        bufsize - pos,
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to