From bcb40a762cbd98b8098c5ed80aee4576d6f9c31a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Thu, 28 Sep 2023 00:40:28 +0200 Subject: [PATCH] lib/idcache: always gracefully handle null cache MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The "get" functions already do this and some callers rely on it also for "add" ones. For completeness also handle it in free_idcache(). Signed-off-by: Thomas Weißschuh --- lib/idcache.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/idcache.c b/lib/idcache.c index c63cca25dc..fa77e7b071 100644 --- a/lib/idcache.c +++ b/lib/idcache.c @@ -34,7 +34,12 @@ struct idcache *new_idcache(void) void free_idcache(struct idcache *ic) { - struct identry *ent = ic->ent; + struct identry *ent; + + if (!ic) + return; + + ent = ic->ent; while (ent) { struct identry *next = ent->next; @@ -51,6 +56,9 @@ static void add_id(struct idcache *ic, char *name, unsigned long int id) struct identry *ent, *x; int w = 0; + if (!ic) + return; + ent = calloc(1, sizeof(struct identry)); if (!ent) return; -- 2.47.3