Changeset: 8a85f7a17b66 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/8a85f7a17b66 Modified Files: monetdb5/modules/atoms/json.c Branch: json-storage Log Message:
Handle allocation failures diffs (38 lines): 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 @@ -256,18 +256,31 @@ JSONfromString(const char *src, size_t * } strcpy(*j, src); jt = JSONparse(*j); - if (jt == NULL) + if (jt == NULL) { return -1; + } if (jt->error) { GDKerror("%s", getExceptionMessageAndState(jt->error)); JSONfree(jt); return -1; } buf = GDKmalloc(2*slen + 1); + if (buf == NULL) { + GDKfree(*j); + JSONfree(jt); + return -1; + } JSONtoStorageString(jt, 0, &buf, &slen); - strncpy(*j, buf - slen, slen); + JSONfree(jt); + GDKfree(*j); + if ((*j = GDKmalloc(slen + 1)) == NULL) { + GDKfree(buf); + JSONfree(jt); + return -1; + } + strncpy(*j, buf, slen); + *len = slen + 1; GDKfree(buf); - JSONfree(jt); return (ssize_t) slen; } _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org