From 3f82d5b1a3e7456571488fd151ae84f9f30ef6cc Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 30 Jan 2023 18:43:36 +0600 Subject: rc: use LIST_FOREACH_SAFE in cleanup() according to the linux manpage, the "safe" variant may not be available on all platform. however we bundle our own `queue.h` so this should not be an issue. --- src/openrc/rc.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/openrc/rc.c b/src/openrc/rc.c index b6bb811b..1b714297 100644 --- a/src/openrc/rc.c +++ b/src/openrc/rc.c @@ -117,8 +117,7 @@ clean_failed(void) static void cleanup(void) { - RC_PID *p1 = LIST_FIRST(&service_pids); - RC_PID *p2; + RC_PID *p, *tmp; if (!rc_in_logger && !rc_in_plugin && applet && (strcmp(applet, "rc") == 0 || strcmp(applet, "openrc") == 0)) @@ -140,16 +139,13 @@ cleanup(void) rc_logger_close(); } - while (p1) { - p2 = LIST_NEXT(p1, entries); - free(p1); - p1 = p2; + LIST_FOREACH_SAFE(p, &service_pids, entries, tmp) { + LIST_REMOVE(p, entries); + free(p); } - - for (p1 = LIST_FIRST(&free_these_pids); p1; /* no-op */) { - p2 = LIST_NEXT(p1, entries); - free(p1); - p1 = p2; + LIST_FOREACH_SAFE(p, &free_these_pids, entries, tmp) { + LIST_REMOVE(p, entries); + free(p); } rc_stringlist_free(main_hotplugged_services); -- cgit v1.2.3