Changeset: 09c01704807a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=09c01704807a
Modified Files:
        gdk/gdk_string.c
        monetdb5/modules/atoms/json.c
Branch: Oct2020
Log Message:

Fix some memory leaks.


diffs (65 lines):

diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -1237,12 +1237,21 @@ GDKanalytical_str_group_concat(BAT *r, B
                }
 
                if (empty) {
-                       if ((single_str = GDKstrdup(str_nil)) == NULL)
-                               goto allocation_error;
+                       if (single_str == NULL) { /* reuse the same buffer, 
resize it when needed */
+                               max_group_length = 1;
+                               if ((single_str = GDKmalloc(max_group_length + 
1)) == NULL)
+                                       goto allocation_error;
+                       } else if (1 > max_group_length) {
+                               max_group_length = 1;
+                               if ((next_single_str = GDKrealloc(single_str, 
max_group_length + 1)) == NULL)
+                                       goto allocation_error;
+                               single_str = next_single_str;
+                       }
+                       strcpy(single_str, str_nil);
                        hasnil = true;
                } else {
                        empty = true;
-                       if (!single_str) { /* reuse the same buffer, resize it 
when needed */
+                       if (single_str == NULL) { /* reuse the same buffer, 
resize it when needed */
                                max_group_length = next_group_length;
                                if ((single_str = GDKmalloc(max_group_length + 
1)) == NULL)
                                        goto allocation_error;
diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -561,8 +561,10 @@ JSONglue(str res, str r, char sep)
        size_t len, l;
        str n;
 
-       if (r == 0 || *r == 0)
+       if (r == 0 || *r == 0) {
+               GDKfree(r);
                return res;
+       }
        len = strlen(r);
        if (res == 0)
                return r;
@@ -1617,14 +1619,14 @@ JSONkeyArray(json *ret, json *js)
        CHECK_JSON(jt);
        if (jt->elm[0].kind == JSON_OBJECT) {
                for (i = jt->elm[0].next; i; i = jt->elm[i].next) {
-                       r = GDKzalloc(jt->elm[i].valuelen + 3);
-                       if (r == NULL) {
-                               JSONfree(jt);
-                               goto memfail;
-                       }
-                       if (jt->elm[i].valuelen)
+                       if (jt->elm[i].valuelen) {
+                               r = GDKzalloc(jt->elm[i].valuelen + 3);
+                               if (r == NULL) {
+                                       JSONfree(jt);
+                                       goto memfail;
+                               }
                                strncpy(r, jt->elm[i].value - 1, 
jt->elm[i].valuelen + 2);
-                       else {
+                       } else {
                                r = GDKstrdup("\"\"");
                                if(r == NULL) {
                                        JSONfree(jt);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to