Skip to content

Commit

Permalink
libsepol: do not leak memory when an error occurs
Browse files Browse the repository at this point in the history
name_list_to_string() and constraint_expr_to_string() both define an
exit label to clean-up dynamically-allocated memory when an error
occurs, but they miss some variables. Free the missing ones too.

This issue has been found using clang's static analyzer.

Signed-off-by: Nicolas Iooss <[email protected]>
  • Loading branch information
fishilico authored and stephensmalley committed Apr 12, 2017
1 parent 8ccd0db commit d88657b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libsepol/src/module_to_cil.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ static int name_list_to_string(char **names, int num_names, char **string)

return 0;
exit:
free(str);
return rc;
}

Expand Down Expand Up @@ -1697,7 +1698,7 @@ static int constraint_expr_to_string(struct policydb *pdb, struct constraint_exp
const char *fmt_str;
const char *attr1;
const char *attr2;
char *names;
char *names = NULL;
char **name_list = NULL;
int num_names = 0;
struct type_set *ts;
Expand Down Expand Up @@ -1798,6 +1799,7 @@ static int constraint_expr_to_string(struct policydb *pdb, struct constraint_exp

names_destroy(&name_list, &num_names);
free(names);
names = NULL;
}

num_params = 0;
Expand Down Expand Up @@ -1887,6 +1889,7 @@ static int constraint_expr_to_string(struct policydb *pdb, struct constraint_exp

exit:
names_destroy(&name_list, &num_names);
free(names);

free(new_val);
free(val1);
Expand Down

0 comments on commit d88657b

Please sign in to comment.