]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/idcache: always gracefully handle null cache
authorThomas Weißschuh <thomas@t-8ch.de>
Wed, 27 Sep 2023 22:40:28 +0000 (00:40 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Thu, 28 Sep 2023 06:20:58 +0000 (08:20 +0200)
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 <thomas@t-8ch.de>
lib/idcache.c

index c63cca25dc52b5e59b7bd280fdfa7bdf846778d2..fa77e7b07127f46d028172e78b3cb85940824ab3 100644 (file)
@@ -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;