summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2023-03-28 09:38:33 +0200
committerDavid Tardon <dtardon@redhat.com>2023-04-12 17:09:41 +0200
commit1abcc826ca0330d4f1e407fad4a71d2f6c537a53 (patch)
tree00856d003f3deb680c263af303da0d63fa8729d9 /src
parent6ff02eac416212300b2afe74d3757805b830ece9 (diff)
downloadsystemd-1abcc826ca0330d4f1e407fad4a71d2f6c537a53.tar.gz
test: use _cleanup_ for UnitFileList hash
Diffstat (limited to 'src')
-rw-r--r--src/test/test-install-root.c6
-rw-r--r--src/test/test-install.c6
-rw-r--r--src/test/test-load-fragment.c6
3 files changed, 6 insertions, 12 deletions
diff --git a/src/test/test-install-root.c b/src/test/test-install-root.c
index ea8015d33d..c866cff022 100644
--- a/src/test/test-install-root.c
+++ b/src/test/test-install-root.c
@@ -578,7 +578,7 @@ TEST(preset_and_list) {
UnitFileState state;
bool got_yes = false, got_no = false;
UnitFileList *fl;
- Hashmap *h;
+ _cleanup_(hashmap_freep) Hashmap *h = NULL;
assert_se(unit_file_get_state(RUNTIME_SCOPE_SYSTEM, root, "preset-yes.service", &state) == -ENOENT);
assert_se(unit_file_get_state(RUNTIME_SCOPE_SYSTEM, root, "preset-no.service", &state) == -ENOENT);
@@ -653,7 +653,7 @@ TEST(preset_and_list) {
assert_se(unit_file_get_state(RUNTIME_SCOPE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(unit_file_get_state(RUNTIME_SCOPE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
- assert_se(h = hashmap_new(&string_hash_ops));
+ assert_se(h = hashmap_new(&unit_file_list_hash_ops_free));
assert_se(unit_file_get_list(RUNTIME_SCOPE_SYSTEM, root, h, NULL, NULL) >= 0);
p = strjoina(root, "/usr/lib/systemd/system/preset-yes.service");
@@ -673,8 +673,6 @@ TEST(preset_and_list) {
assert_se(IN_SET(fl->state, UNIT_FILE_DISABLED, UNIT_FILE_STATIC, UNIT_FILE_INDIRECT, UNIT_FILE_ALIAS));
}
- unit_file_list_free(h);
-
assert_se(got_yes && got_no);
}
diff --git a/src/test/test-install.c b/src/test/test-install.c
index eb02795096..9fba0a8ca8 100644
--- a/src/test/test-install.c
+++ b/src/test/test-install.c
@@ -20,7 +20,7 @@ static void dump_changes(InstallChange *c, unsigned n) {
}
int main(int argc, char* argv[]) {
- Hashmap *h;
+ _cleanup_(hashmap_freep) Hashmap *h = NULL;
UnitFileList *p;
int r;
const char *const files[] = { "avahi-daemon.service", NULL };
@@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
test_setup_logging(LOG_DEBUG);
- h = hashmap_new(&string_hash_ops);
+ h = hashmap_new(&unit_file_list_hash_ops_free);
r = unit_file_get_list(RUNTIME_SCOPE_SYSTEM, NULL, h, NULL, NULL);
assert_se(r == 0);
@@ -48,8 +48,6 @@ int main(int argc, char* argv[]) {
unit_file_state_to_string(p->state));
}
- unit_file_list_free(h);
-
log_info("/*** enable **/");
r = unit_file_enable(RUNTIME_SCOPE_SYSTEM, 0, NULL, (char**) files, &changes, &n_changes);
diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c
index 39fcdcd94a..708abb7026 100644
--- a/src/test/test-load-fragment.c
+++ b/src/test/test-load-fragment.c
@@ -41,10 +41,10 @@ STATIC_DESTRUCTOR_REGISTER(runtime_dir, rm_rf_physical_and_freep);
TEST_RET(unit_file_get_set) {
int r;
- Hashmap *h;
+ _cleanup_(hashmap_freep) Hashmap *h = NULL;
UnitFileList *p;
- h = hashmap_new(&string_hash_ops);
+ h = hashmap_new(&unit_file_list_hash_ops_free);
assert_se(h);
r = unit_file_get_list(RUNTIME_SCOPE_SYSTEM, NULL, h, NULL, NULL);
@@ -59,8 +59,6 @@ TEST_RET(unit_file_get_set) {
HASHMAP_FOREACH(p, h)
printf("%s = %s\n", p->path, unit_file_state_to_string(p->state));
- unit_file_list_free(h);
-
return 0;
}