test: Fix the ASan tests
This change makes the tests work with ASan again. It also fixes a memory
leak in `seccomp_action_is_available()`.
Bug: None
Test: make clean && make USE_ASAN=yes tests
Change-Id: I5a6c378127704ac06f8747cc40bbb74a41401cb2
diff --git a/system.c b/system.c
index 52a07c5..10e1499 100644
--- a/system.c
+++ b/system.c
@@ -478,7 +478,7 @@
return -ERANGE;
}
-static int seccomp_action_is_available(const char *wanted)
+static bool seccomp_action_is_available(const char *wanted)
{
if (is_android()) {
/*
@@ -487,7 +487,7 @@
* TODO(crbug.com/978022, jorgelo): Remove once the denial is
* fixed.
*/
- return 0;
+ return false;
}
const char actions_avail_path[] =
"/proc/sys/kernel/seccomp/actions_avail";
@@ -495,7 +495,7 @@
if (!f) {
pwarn("fopen(%s) failed", actions_avail_path);
- return 0;
+ return false;
}
char *actions_avail = NULL;
@@ -503,7 +503,7 @@
if (getline(&actions_avail, &buf_size, f) < 0) {
pwarn("getline() failed");
free(actions_avail);
- return 0;
+ return false;
}
/*
@@ -512,7 +512,9 @@
* seccomp actions which include other actions though, so we're good for
* now. Eventually we might want to split the string by spaces.
*/
- return strstr(actions_avail, wanted) != NULL;
+ bool available = strstr(actions_avail, wanted) != NULL;
+ free(actions_avail);
+ return available;
}
int seccomp_ret_log_available(void)