mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-28 12:58:07 +00:00
parser: fix leaks from variable refactoring
Fix issues introduced in coverity's snapshot 89167 - CID 532796: (#4 of 4): Resource leak (RESOURCE_LEAK) Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
This commit is contained in:
parent
e4f3ef72ab
commit
efb13aac0a
@ -140,6 +140,7 @@ int process_profile_variables(Profile *prof)
|
|||||||
int error = 0;
|
int error = 0;
|
||||||
variable *saved_exec_path = NULL;
|
variable *saved_exec_path = NULL;
|
||||||
variable *saved_attach_path = NULL;
|
variable *saved_attach_path = NULL;
|
||||||
|
variable *tmp = NULL;
|
||||||
|
|
||||||
/* needs to be before PROFILE_NAME_VARIABLE so that variable will
|
/* needs to be before PROFILE_NAME_VARIABLE so that variable will
|
||||||
* have the correct name
|
* have the correct name
|
||||||
@ -185,18 +186,25 @@ cleanup:
|
|||||||
* don't support that yet.
|
* don't support that yet.
|
||||||
*/
|
*/
|
||||||
if (prof->attachment) {
|
if (prof->attachment) {
|
||||||
symtab::delete_var(PROFILE_EXEC_VAR);
|
tmp = symtab::delete_var(PROFILE_EXEC_VAR);
|
||||||
if (saved_exec_path)
|
delete tmp;
|
||||||
|
if (saved_exec_path) {
|
||||||
symtab::add_var(*saved_exec_path);
|
symtab::add_var(*saved_exec_path);
|
||||||
|
delete saved_exec_path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cleanup_attach:
|
cleanup_attach:
|
||||||
if (prof->attachment) {
|
if (prof->attachment) {
|
||||||
symtab::delete_var(PROFILE_ATTACH_VAR);
|
tmp = symtab::delete_var(PROFILE_ATTACH_VAR);
|
||||||
if (saved_attach_path)
|
delete tmp;
|
||||||
|
if (saved_attach_path) {
|
||||||
symtab::add_var(*saved_attach_path);
|
symtab::add_var(*saved_attach_path);
|
||||||
|
delete saved_attach_path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cleanup_name:
|
cleanup_name:
|
||||||
symtab::delete_var(PROFILE_NAME_VARIABLE);
|
tmp = symtab::delete_var(PROFILE_NAME_VARIABLE);
|
||||||
|
delete tmp;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return error;
|
return error;
|
||||||
|
@ -139,13 +139,16 @@ variable *symtab::get_set_var(const char *name)
|
|||||||
char *var_name = variable::process_var(name);
|
char *var_name = variable::process_var(name);
|
||||||
variable *var = lookup_existing_symbol(var_name);
|
variable *var = lookup_existing_symbol(var_name);
|
||||||
if (!var) {
|
if (!var) {
|
||||||
return var;
|
goto out;
|
||||||
}
|
}
|
||||||
if (var->type != sd_set) {
|
if (var->type != sd_set) {
|
||||||
PERROR("Variable %s is not a set variable\n", var_name);
|
PERROR("Variable %s is not a set variable\n", var_name);
|
||||||
return nullptr;
|
var = nullptr;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
var->expand_variable();
|
var->expand_variable();
|
||||||
|
out:
|
||||||
|
free(var_name);
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,12 +157,14 @@ variable *symtab::get_boolean_var(const char *name)
|
|||||||
char *var_name = variable::process_var(name);
|
char *var_name = variable::process_var(name);
|
||||||
variable *var = lookup_existing_symbol(var_name);
|
variable *var = lookup_existing_symbol(var_name);
|
||||||
if (!var) {
|
if (!var) {
|
||||||
return var;
|
goto out;
|
||||||
}
|
}
|
||||||
if (var->type != sd_boolean) {
|
if (var->type != sd_boolean) {
|
||||||
PERROR("Variable %s is not a boolean variable\n", var_name);
|
PERROR("Variable %s is not a boolean variable\n", var_name);
|
||||||
return nullptr;
|
var = nullptr;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
free(var_name);
|
free(var_name);
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
|
@ -265,6 +265,7 @@ int variable::expand_by_alternation(char **name)
|
|||||||
|
|
||||||
int variable::expand_variable()
|
int variable::expand_variable()
|
||||||
{
|
{
|
||||||
|
char *name = NULL;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
if (type == sd_boolean) {
|
if (type == sd_boolean) {
|
||||||
@ -290,7 +291,7 @@ int variable::expand_variable()
|
|||||||
expanded.insert(value); /* no var left to expand */
|
expanded.insert(value); /* no var left to expand */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char *name = variable::process_var(var.c_str());
|
name = variable::process_var(var.c_str());
|
||||||
variable *ref = symtab::lookup_existing_symbol(name);
|
variable *ref = symtab::lookup_existing_symbol(name);
|
||||||
if (!ref) {
|
if (!ref) {
|
||||||
PERROR("Failed to find declaration for: %s\n", var.c_str());
|
PERROR("Failed to find declaration for: %s\n", var.c_str());
|
||||||
@ -321,6 +322,7 @@ int variable::expand_variable()
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
free(name);
|
||||||
expanding = false;
|
expanding = false;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user