Skip to contentSkip to conversation

samples/landlock: fix path_list memory leak

PATCH In review [email protected] 2 participants 2 messages Apr 28, 2021 – Apr 29, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 samples/landlock: fix path_list memory leak

From: Tom Rix <[email protected]>

Clang static analysis reports this error

sandboxer.c:134:8: warning: Potential leak of memory
pointed to by 'path_list'

        ret = 0;
              ^

path_list is allocated in parse_path() but never freed.

---
v2:
- Remove NULL ptr check

---
 samples/landlock/sandboxer.c | 1 +
 1 file changed, 1 insertion(+)
samples/landlock/sandboxer.c +1 -0
index 7a15910d2171..8859fc193542 100644
@@ -134,6 +134,7 @@ static int populate_ruleset(
 	ret = 0;
 
 out_free_name:
+	free(path_list);
 	free(env_path_name);
 	return ret;
 }
Signature · 1 line
2.26.3
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · On 28/04/2021 23:38, [email protected] wrote:

From: Tom Rix <[email protected]>

Clang static analysis reports this error

sandboxer.c:134:8: warning: Potential leak of memory
pointed to by 'path_list'

        ret = 0;
              ^

path_list is allocated in parse_path() but never freed.

Previous version:
https://lore.kernel.org/r/[email protected]

Quoted 20 lines

---
v2:
- Remove NULL ptr check

---
 samples/landlock/sandboxer.c | 1 +
 1 file changed, 1 insertion(+)
samples/landlock/sandboxer.c +1 -0
index 7a15910d2171..8859fc193542 100644
@@ -134,6 +134,7 @@ static int populate_ruleset(
 	ret = 0;
 
 out_free_name:
+	free(path_list);
 	free(env_path_name);
 	return ret;
 }