git: c7c3f8dbcfae - stable/14 - pkg: make sure the repositories have at least an url
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 06 Mar 2025 15:39:59 UTC
The branch stable/14 has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=c7c3f8dbcfaeac5b4f881d329cf6cec92a8521df
commit c7c3f8dbcfaeac5b4f881d329cf6cec92a8521df
Author: Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2025-01-15 08:06:55 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2025-03-06 15:37:51 +0000
pkg: make sure the repositories have at least an url
While here, factorize code to free the repository structure
(cherry picked from commit eccf736c3ce6e9566fa9923080b4c24ee7f9ae2a)
---
usr.sbin/pkg/config.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c
index ce73a08d93f3..521360c642d6 100644
--- a/usr.sbin/pkg/config.c
+++ b/usr.sbin/pkg/config.c
@@ -1,9 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
+ * Copyright (c) 2014-2025 Baptiste Daroussin <bapt@FreeBSD.org>
* Copyright (c) 2013 Bryan Drewery <bdrewery@FreeBSD.org>
- * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -333,6 +332,16 @@ parse_mirror_type(struct repository *r, const char *mt)
r->mirror_type = MIRROR_NONE;
}
+static void
+repo_free(struct repository *r)
+{
+ free(r->name);
+ free(r->url);
+ free(r->fingerprints);
+ free(r->pubkey);
+ free(r);
+}
+
static bool
parse_signature_type(struct repository *repo, const char *st)
{
@@ -345,11 +354,7 @@ parse_signature_type(struct repository *repo, const char *st)
else {
warnx("Signature type %s is not supported for bootstraping,"
" ignoring repository %s", st, repo->name);
- free(repo->url);
- free(repo->name);
- free(repo->fingerprints);
- free(repo->pubkey);
- free(repo);
+ repo_free(repo);
return false;
}
return (true);
@@ -393,13 +398,16 @@ parse_repo(const ucl_object_t *o)
} else if (strcasecmp(key, "enabled") == 0) {
if ((cur->type != UCL_BOOLEAN) ||
!ucl_object_toboolean(cur)) {
- free(repo->url);
- free(repo->name);
- free(repo);
+ repo_free(repo);
return;
}
}
}
+ /* At least we need an url */
+ if (repo->url == NULL) {
+ repo_free(repo);
+ return;
+ }
STAILQ_INSERT_TAIL(&repositories, repo, next);
return;
}