From: Thomas Weißschuh Date: Wed, 27 Sep 2023 22:40:28 +0000 (+0200) Subject: lib/idcache: always gracefully handle null cache X-Git-Tag: v2.40-rc1~222^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bcb40a762cbd98b8098c5ed80aee4576d6f9c31a;p=thirdparty%2Futil-linux.git lib/idcache: always gracefully handle null cache 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 --- 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;