From 2f953ea76b5779a73a540777dfb450982802e4f8 Mon Sep 17 00:00:00 2001
From: vdutta <vivek.dutta@iopsys.eu>
Date: Tue, 24 May 2022 10:54:20 +0530
Subject: [PATCH] Fix segfault when no container is running

---
 src/swmod_lxc.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/swmod_lxc.c b/src/swmod_lxc.c
index 8c9f11a..44e0f8f 100644
--- a/src/swmod_lxc.c
+++ b/src/swmod_lxc.c
@@ -257,6 +257,11 @@ void populate_lxc_environment(void)
 	int i, lxc_nbr;
 
 	lxc_nbr = list_all_containers(lxcpath, NULL, &clist);
+	if (clist == NULL || lxc_nbr == 0) {
+		PRINT_INFO("Empty container list, return");
+		return;
+	}
+
 	for (i = 0; i < lxc_nbr && i < (MAX_ENV - LXC_START_INDEX); i++) {
 		struct lxc_container *ct = clist[i];
 		bool ct_running = ct->is_running(ct);
-- 
GitLab