Changeset: c0a98c41bb4a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c0a98c41bb4a
Added Files:
        sql/test/merge-partitions/Tests/mergepart03.sql
Modified Files:
        sql/backends/monet5/sql_cat.c
        sql/common/sql_mem.c
        sql/include/sql_mem.h
        sql/storage/store.c
Branch: merge-partitions
Log Message:

Memory leaks


diffs (253 lines):

diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -279,6 +279,8 @@ alter_table_add_value_partition(mvc *sql
        }
 
 finish:
+       if(msg && b)
+               BBPreclaim(b);
        return msg;
 }
 
diff --git a/sql/common/sql_mem.c b/sql/common/sql_mem.c
--- a/sql/common/sql_mem.c
+++ b/sql/common/sql_mem.c
@@ -117,37 +117,6 @@ void *sa_alloc( sql_allocator *sa, size_
        return r;
 }
 
-void *sa_push( sql_allocator *sa, void *area, size_t sz )
-{
-       sz = round16(sz);
-       if (sz > (SA_BLOCK-sa->used)) {
-               if (sa->nr >= sa->size) {
-                       char **tmp;
-                       sa->size *=2;
-                       tmp = RENEW_ARRAY(char*,sa->blks,sa->size);
-                       if (tmp == NULL) {
-                               sa->size /= 2; /* undo */
-                               return NULL;
-                       }
-                       sa->blks = tmp;
-               }
-               if (sz > SA_BLOCK) {
-                       sa->blks[sa->nr] = sa->blks[sa->nr-1];
-                       sa->blks[sa->nr-1] = area;
-                       sa->nr ++;
-                       sa->usedmem += sz;
-               } else {
-                       sa->blks[sa->nr] = area;
-                       sa->nr ++;
-                       sa->used = sz;
-                       sa->usedmem += SA_BLOCK;
-               }
-       } else {
-               sa->used += sz;
-       }
-       return area;
-}
-
 #undef sa_zalloc
 void *sa_zalloc( sql_allocator *sa, size_t sz )
 {
diff --git a/sql/include/sql_mem.h b/sql/include/sql_mem.h
--- a/sql/include/sql_mem.h
+++ b/sql/include/sql_mem.h
@@ -63,7 +63,6 @@ typedef struct sql_allocator {
 extern sql_allocator *sa_create(void);
 extern sql_allocator *sa_reset( sql_allocator *sa );
 extern void *sa_alloc( sql_allocator *sa,  size_t sz );
-extern void *sa_push( sql_allocator *sa, void *area, size_t sz );
 extern void *sa_zalloc( sql_allocator *sa,  size_t sz );
 extern void *sa_realloc( sql_allocator *sa,  void *ptr, size_t sz, size_t osz 
);
 extern void sa_destroy( sql_allocator *sa );
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -139,6 +139,17 @@ column_destroy(sql_column *c)
                store_funcs.destroy_col(NULL, c);
 }
 
+/*static void
+member_destroy(sql_part *pt)
+{
+       if(isRangePartitionTable(pt->t)) {
+               GDKfree(pt->part.range.minvalue);
+               GDKfree(pt->part.range.maxvalue);
+       } else if(isListPartitionTable(pt->t)) {
+               BBPrelease(pt->part.values);
+       }
+}*/
+
 void
 table_destroy(sql_table *t)
 {
@@ -567,7 +578,6 @@ load_range_partition(sql_trans *tr, sql_
        if((rid = table_funcs.rids_next(rs)) != oid_nil) {
                void *v = table_funcs.column_find_value(tr, 
find_sql_column(ranges, "minimum"), rid);
                ssize_t e = ATOMfromstr(tpe, &min, &min_length, v);
-               sa_push(tr->sa, min, min_length);
                _DELETE(v);
                if(e < 0) {
                        table_funcs.rids_destroy(rs);
@@ -576,9 +586,9 @@ load_range_partition(sql_trans *tr, sql_
 
                v = table_funcs.column_find_value(tr, find_sql_column(ranges, 
"maximum"), rid);
                e = ATOMfromstr(tpe, &max, &max_length, v);
-               sa_push(tr->sa, max, max_length);
                _DELETE(v);
                if(e < 0) {
+                       GDKfree(min);
                        table_funcs.rids_destroy(rs);
                        return -1;
                }
@@ -4606,26 +4616,29 @@ sql_trans_add_range_partition(sql_trans 
        ssize_t (*atomtostr)(str *, size_t *, const void *) = 
BATatoms[tpe].atomToStr;
        str str_min = NULL, str_max = NULL;
        size_t length = 0;
-       ssize_t res;
        oid rid;
-       int *v;
-
-       res = atomtostr(&str_min, &length, min);
-       if(res == 0)
-               return -1;
-       sa_push(tr->sa, str_min, length);
-       if(length > STORAGE_MAX_VALUE_LENGTH)
-               return -2;
-
-       res = atomtostr(&str_max, &length, max);
-       if(res == 0)
-               return -1;
-       sa_push(tr->sa, str_max, length);
-       if(length > STORAGE_MAX_VALUE_LENGTH)
-               return -3;
-
+       int *v, res = 0;
+
+       if(atomtostr(&str_min, &length, min) == 0) {
+               res = -1;
+               goto finish;
+       }
+       if(length > STORAGE_MAX_VALUE_LENGTH) {
+               res = -2;
+               goto finish;
+       }
+
+       if(atomtostr(&str_max, &length, max) == 0) {
+               res = -1;
+               goto finish;
+       }
+       if(length > STORAGE_MAX_VALUE_LENGTH) {
+               res = -3;
+               goto finish;
+       }
+
+       base_init(tr->sa, &p->base, pt->base.id, TR_NEW, pt->base.name);
        pt->p = mt;
-       base_init(tr->sa, &p->base, pt->base.id, TR_NEW, pt->base.name);
        p->t = pt;
        p->tpe = tpe;
 
@@ -4636,8 +4649,10 @@ sql_trans_add_range_partition(sql_trans 
        p->part.range.maxlength = smax;
 
        *err = cs_add_sorted(&mt->members, p, TR_NEW, 
sql_range_part_validate_and_insert);
-       if(*err)
-               return -4;
+       if(*err) {
+               res = -4;
+               goto finish;
+       }
 
        /* add merge table dependency */
        sql_trans_create_dependency(tr, pt->base.id, mt->base.id, 
TABLE_DEPENDENCY);
@@ -4650,7 +4665,12 @@ sql_trans_add_range_partition(sql_trans 
        table_funcs.table_insert(tr, ranges, &pt->base.id, v, str_min, str_max);
        _DELETE(v);
 
-       return 0;
+finish:
+       if(str_min)
+               GDKfree(str_min);
+       if(str_max)
+               GDKfree(str_max);
+       return res;
 }
 
 int
@@ -4665,21 +4685,15 @@ sql_trans_add_value_partition(sql_trans 
        str next_value = NULL;
        ptr next_entry = NULL;
        size_t length = 0;
-       ssize_t res;
        oid rid;
        int *v, i = 0;
        BUN bp, bq;
        BATiter bi = bat_iterator(b);
 
-       /* add merge table dependency */
-       sql_trans_create_dependency(tr, pt->base.id, mt->base.id, 
TABLE_DEPENDENCY);
+       base_init(tr->sa, &p->base, pt->base.id, TR_NEW, pt->base.name);
        pt->p = mt;
-       base_init(tr->sa, &p->base, pt->base.id, TR_NEW, pt->base.name);
        p->t = pt;
        p->tpe = tpe;
-       cs_add(&mt->members, p, TR_NEW);
-       mt->s->base.wtime = mt->base.wtime = tr->wtime = tr->wstime;
-       table_funcs.table_insert(tr, sysobj, &mt->base.id, p->base.name, 
&p->base.id);
 
        rid = table_funcs.column_find_row(tr, find_sql_column(partitions, 
"table_id"), &mt->base.id, NULL);
        assert(!is_oid_nil(rid));
@@ -4688,10 +4702,12 @@ sql_trans_add_value_partition(sql_trans 
        BATloop(b,bp,bq) {
                next_value = NULL;
                next_entry = (ptr) BUNtail(bi, bp);
-               res = atomtostr(&next_value, &length, next_entry);
-               if(res == 0)
+               if(atomtostr(&next_value, &length, next_entry) == 0) {
+                       _DELETE(v);
                        return -i - 1;
+               }
                if(length > STORAGE_MAX_VALUE_LENGTH) {
+                       _DELETE(v);
                        GDKfree(next_value);
                        return -i - 1;
                }
@@ -4706,6 +4722,12 @@ sql_trans_add_value_partition(sql_trans 
        p->part.values = b->batCacheid;
        BBPretain(b->batCacheid);
 
+       cs_add(&mt->members, p, TR_NEW);
+       /* add merge table dependency */
+       sql_trans_create_dependency(tr, pt->base.id, mt->base.id, 
TABLE_DEPENDENCY);
+       table_funcs.table_insert(tr, sysobj, &mt->base.id, p->base.name, 
&p->base.id);
+       mt->s->base.wtime = mt->base.wtime = tr->wtime = tr->wstime;
+
        return 0;
 }
 
diff --git a/sql/test/merge-partitions/Tests/mergepart03.sql 
b/sql/test/merge-partitions/Tests/mergepart03.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/merge-partitions/Tests/mergepart03.sql
@@ -0,0 +1,18 @@
+CREATE MERGE TABLE listparts (a int, b varchar(32)) PARTITION BY RANGE (a);
+CREATE TABLE subtable1 (a int, b varchar(32));
+CREATE TABLE subtable2 (a int, b varchar(32));
+
+START TRANSACTION;
+ALTER TABLE listparts ADD TABLE subtable1 AS PARTITION BETWEEN -4 AND 12;
+SELECT COUNT(*) from range_partitions;
+ROLLBACK;
+
+SELECT COUNT(*) from range_partitions;
+ALTER TABLE listparts ADD TABLE subtable2 AS PARTITION BETWEEN -4 AND 12;
+SELECT COUNT(*) from range_partitions;
+
+ALTER TABLE listparts DROP TABLE subtable2;
+DROP TABLE listparts;
+DROP TABLE subtable1;
+DROP TABLE subtable2;
+SELECT COUNT(*) from range_partitions;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to