From: Michael Schroeder Date: Mon, 18 May 2026 10:48:09 +0000 (+0200) Subject: Move dirs reallocation from dirpool_make_dirtraverse to dirpool_add_dir X-Git-Tag: 0.7.38~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8a3fcbd4e9b1287ff51e2c8cf1c6b6be9f1f600;p=thirdparty%2Flibsolv.git Move dirs reallocation from dirpool_make_dirtraverse to dirpool_add_dir repo_add_solv does not use the correct DIR_BLOCK allocation, so we need to extend the dirs array the first time we add a new directory. We used to do this in dirpool_make_dirtraverse, but since commit fa35e8672b478c410429d403b887277d7b17e57d the dirtraverse array is no longer created when calling dirpool_add_dir. So we now do it the first time the hash is created. --- diff --git a/src/dirpool.c b/src/dirpool.c index 6fc2c0b7..45a391a1 100644 --- a/src/dirpool.c +++ b/src/dirpool.c @@ -82,9 +82,9 @@ void dirpool_make_dirtraverse(Dirpool *dp) { Id parent, i, *dirtraverse; + dp->dirtraverse = solv_free(dp->dirtraverse); if (!dp->ndirs) return; - dp->dirs = solv_extend_resize(dp->dirs, dp->ndirs, sizeof(Id), DIR_BLOCK); dirtraverse = solv_calloc_block(dp->ndirs, sizeof(Id), DIR_BLOCK); for (i = 0; i < dp->ndirs; i++) { @@ -174,7 +174,12 @@ dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create) /* grow hash table if load factor exceeds 50% */ if ((Hashval)dp->ndirs * 2 >= dp->dirhashmask) - dirpool_resize_hash(dp, DIR_BLOCK); + { + /* hack: repo_add_solv will not use DIR_BLOCK, so realloc here */ + if (!dp->dirhashmask) + dp->dirs = solv_extend_resize(dp->dirs, dp->ndirs, sizeof(Id), DIR_BLOCK); + dirpool_resize_hash(dp, DIR_BLOCK); + } ht = dp->dirhashtbl; hm = dp->dirhashmask; diff --git a/src/repo_solv.c b/src/repo_solv.c index b1827062..4ddee644 100644 --- a/src/repo_solv.c +++ b/src/repo_solv.c @@ -873,6 +873,7 @@ repo_add_solv(Repo *repo, FILE *fp, int flags) /******* Part 3: Dirs ***********************************************/ if (numdir) { + /* note that we do not use DIR_BLOCK here. See comment in dirpool_add_dir */ data.dirpool.dirs = solv_malloc2(numdir, sizeof(Id)); data.dirpool.ndirs = numdir; data.dirpool.dirs[0] = 0; /* dir 0: virtual root */