Skip to content
Snippets Groups Projects
Commit 3cdd4a4b authored by Manoj Gupta's avatar Manoj Gupta
Browse files

Fix static analyzer warnings.

Fix the following warnings:

system/sepolicy/tools/sepolicy-analyze/neverallow.c:346:9: warning:
Potential leak of memory pointed to by '__s1'
system/sepolicy/tools/sepolicy-analyze/neverallow.c:346:9: warning:
Potential leak of memory pointed to by 'id'
system/sepolicy/tools/sepolicy-analyze/neverallow.c:364:13: warning:
Potential leak of memory pointed to by 'classperms'
system/sepolicy/tools/sepolicy-analyze/neverallow.c:364:13: warning:
Potential leak of memory pointed to by 'node'

Bug: b/27101951
Test:Warnings are gone.
Change-Id: Ib9b2e0b9f19950b4b764d438ee58340e6c022ef5
parent 5c41d40e
No related branches found
No related tags found
No related merge requests found
...@@ -261,6 +261,7 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end, ...@@ -261,6 +261,7 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end,
node->next = classperms; node->next = classperms;
classperms = node; classperms = node;
free(id); free(id);
id = NULL;
} while (p < end && openparens); } while (p < end && openparens);
if (p == end) if (p == end)
...@@ -328,6 +329,8 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end, ...@@ -328,6 +329,8 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end,
if (!strcmp(id, "*")) { if (!strcmp(id, "*")) {
for (node = classperms; node; node = node->next) for (node = classperms; node; node = node->next)
node->data = ~0; node->data = ~0;
free(id);
id = NULL;
continue; continue;
} }
...@@ -344,6 +347,7 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end, ...@@ -344,6 +347,7 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end,
node->data |= 1U << (perm->s.value - 1); node->data |= 1U << (perm->s.value - 1);
} }
free(id); free(id);
id = NULL;
} while (p < end && openparens); } while (p < end && openparens);
if (p == end) if (p == end)
...@@ -364,6 +368,12 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end, ...@@ -364,6 +368,12 @@ static int read_classperms(policydb_t *policydb, char **ptr, char *end,
*ptr = p; *ptr = p;
return 0; return 0;
err: err:
// free classperms memory
for (node = classperms; node; ) {
class_perm_node_t *freeptr = node;
node = node->next;
free(freeptr);
}
return -1; return -1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment