libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

commit aa218df8385a08b6cd2897f9fd927fd3fab04d31
parent 920fd1d65f7c4c0d97d686644c761b946f0d213e
Author: Remy Noulin <loader2x@gmail.com>
Date:   Thu, 20 Oct 2022 21:14:11 +0200

Fix null dereference introduced in b62563e (fix memory leaks)

release/libsheepy.h             |  2 +-
src/json/libsheepyCSmallArray.c |  2 +-
src/json/libsheepyCSmallDict.c  |  9 +++++----
src/json/libsheepyCSmallJson.c  | 11 ++++++-----
src/libsheepy.h                 |  2 +-
5 files changed, 14 insertions(+), 12 deletions(-)

Diffstat:
Mrelease/libsheepy.h | 2+-
Msrc/json/libsheepyCSmallArray.c | 2+-
Msrc/json/libsheepyCSmallDict.c | 9+++++----
Msrc/json/libsheepyCSmallJson.c | 11++++++-----
Msrc/libsheepy.h | 2+-
5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/release/libsheepy.h b/release/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.10.2" +#define LIBSHEEPY_VERSION "2.2.10.3" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME diff --git a/src/json/libsheepyCSmallArray.c b/src/json/libsheepyCSmallArray.c @@ -1581,7 +1581,7 @@ internal void disposeSmallArray(smallArrayt *self) { if (self->a) { // free containers of baset object to avoid leaks forEachSArray(self->a, o) { - if (o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET)) { + if (o && o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET)) { free(o); } } diff --git a/src/json/libsheepyCSmallDict.c b/src/json/libsheepyCSmallDict.c @@ -1109,12 +1109,13 @@ internal void disposeSmallDict(smallDictt *self) { forEachSDict(self->d, e) { if (e->key) { free(e->key); - } - // free containers of baset object to avoid leaks - if (e->data && e->data->type == CONTAINER && (((sContainert*)e->data)->dataType == SH_DT_BASET)) { - free(e->data); + // free containers of baset object to avoid leaks + // e->data is valid only when e->key is not null + if (e->data && e->data->type == CONTAINER && (((sContainert*)e->data)->dataType == SH_DT_BASET)) { + free(e->data); } } + } free(self->d); resetSmallDict(self); } diff --git a/src/json/libsheepyCSmallJson.c b/src/json/libsheepyCSmallJson.c @@ -2867,12 +2867,13 @@ internal void disposeSmallJson(smallJsont *self) { forEachSDict(self->top, e) { if (e->key) { free(e->key); - } - // free containers of baset object to avoid leaks - if (e->data && e->data->type == CONTAINER && (((sContainert*)e->data)->dataType == SH_DT_BASET)) { - free(e->data); + // free containers of baset object to avoid leaks + // e->data is valid only when e->key is not null + if (e->data && e->data->type == CONTAINER && (((sContainert*)e->data)->dataType == SH_DT_BASET)) { + free(e->data); } } + } free(self->top); self->top = NULL; } @@ -2881,7 +2882,7 @@ internal void disposeSmallJson(smallJsont *self) { if (self->topA) { // free containers of baset object to avoid leaks forEachSArray(self->topA, o) { - if (o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET)) { + if (o && o->type == CONTAINER && (((sContainert*)o)->dataType == SH_DT_BASET)) { free(o); } } diff --git a/src/libsheepy.h b/src/libsheepy.h @@ -98,7 +98,7 @@ // version accoring to the version package: Release.Major.minor.patch // https://noulin.net/version/file/README.md.html -#define LIBSHEEPY_VERSION "2.2.10.2" +#define LIBSHEEPY_VERSION "2.2.10.3" #ifndef SH_PREFIX #define SH_PREFIX(NAME) NAME