diff options
| author | 2023-04-03 16:09:48 -0400 | |
|---|---|---|
| committer | 2023-04-03 16:09:48 -0400 | |
| commit | fbe5f413811df3712c2b3cd7c037afeb30313286 (patch) | |
| tree | 986c8a230e9013d5b707fe792f12faa8d494be17 | |
| parent | test: test json api (diff) | |
native: fix non-zeroed initialization
When we initialize an slist but it's meant to be empty,
it might not be zero-allocated and thus recognize it's null.
Therefore, explicitly zero-initialize jurl_cleanup->slist.
| -rw-r--r-- | src/cleanup.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/cleanup.c b/src/cleanup.c index abc55b7..f47c374 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -18,6 +18,17 @@ void jurl_do_cleanup(struct jurl_cleanup **src) { struct jurl_cleanup *register_cleanup(struct jurl_cleanup **prev, enum jurl_cleanup_type type) { struct jurl_cleanup *out = malloc(sizeof(struct jurl_cleanup)); + + switch (type) { + case JURL_CLEANUP_TYPE_SLIST: + out->slist = NULL; // we malloced + break; + default: + free(out); + janet_panic("unknown cleanup type in register_cleanup"); + return NULL; + } + out->next = *prev; *prev = out; out->type = type; |
