diff options
| author | Pierre Pronchery <khorben@FreeBSD.org> | 2026-06-24 19:47:19 +0000 |
|---|---|---|
| committer | Pierre Pronchery <khorben@FreeBSD.org> | 2026-06-29 05:21:29 +0000 |
| commit | ebcc78644e0cbc4141807c0887ef8d902cb91bb4 (patch) | |
| tree | da5efe7c3c9ae0f140e24a1b69833a476fb09f01 /libpkgconf/cache.c | |
| parent | 6294b6ab217a2d5f1d2bc23a64505a228294c508 (diff) | |
Diffstat (limited to 'libpkgconf/cache.c')
| -rw-r--r-- | libpkgconf/cache.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libpkgconf/cache.c b/libpkgconf/cache.c index 883c8df7127e..4f5f3cb62b97 100644 --- a/libpkgconf/cache.c +++ b/libpkgconf/cache.c @@ -2,6 +2,8 @@ * cache.c * package object cache * + * SPDX-License-Identifier: pkgconf + * * Copyright (c) 2013 pkgconf authors (see AUTHORS). * * Permission to use, copy, modify, and/or distribute this software for any @@ -127,18 +129,31 @@ pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg) pkgconf_pkg_ref(client, pkg); - PKGCONF_TRACE(client, "added @%p to cache", pkg); + pkgconf_pkg_t **new_table; /* mark package as cached */ pkg->flags |= PKGCONF_PKG_PROPF_CACHED; ++client->cache_count; - client->cache_table = pkgconf_reallocarray(client->cache_table, + new_table = pkgconf_reallocarray(client->cache_table, client->cache_count, sizeof (void *)); + + /* if we are out of memory, roll back adding to cache and bail */ + if (new_table == NULL) + { + --client->cache_count; + pkg->flags &= ~PKGCONF_PKG_PROPF_CACHED; + pkgconf_pkg_unref(client, pkg); + return; + } + + client->cache_table = new_table; client->cache_table[client->cache_count - 1] = pkg; qsort(client->cache_table, client->cache_count, sizeof(void *), cache_member_sort_cmp); + + PKGCONF_TRACE(client, "added @%p to cache", pkg); } /* @@ -193,8 +208,11 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg) client->cache_count--; if (client->cache_count > 0) { - client->cache_table = pkgconf_reallocarray(client->cache_table, + pkgconf_pkg_t **new_table = pkgconf_reallocarray(client->cache_table, client->cache_count, sizeof(void *)); + + if (new_table != NULL) + client->cache_table = new_table; } else { |
