Skip to content

Commit

Permalink
checkpolicy/module_compiler: cleanup stack on exit
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
  • Loading branch information
cgzones committed Nov 8, 2023
1 parent 8004b9b commit 6aaff88
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion checkpolicy/checkmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "queue.h"
#include "checkpolicy.h"
#include "module_compiler.h"
#include "parse_util.h"

extern int mlspol;
Expand Down Expand Up @@ -365,13 +366,15 @@ int main(int argc, char **argv)
goto exit;
}

module_compiler_cleanup();
sepol_sidtab_destroy(&sidtab);
policydb_destroy(&modpolicydb);

return 0;

exit:
sepol_sidtab_destroy(&sidtab);
module_compiler_cleanup();
sepol_sidtab_destroy(&sidtab);
policydb_destroy(&modpolicydb);

return 1;
Expand Down
3 changes: 3 additions & 0 deletions checkpolicy/checkpolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@

#include "queue.h"
#include "checkpolicy.h"
#include "module_compiler.h"
#include "parse_util.h"

extern policydb_t *policydbp;
Expand Down Expand Up @@ -1332,13 +1333,15 @@ int main(int argc, char **argv)
}

out:
module_compiler_cleanup();
sepol_sidtab_destroy(&sidtab);
policydb_destroy(&policydb);
policydb_destroy(&parse_policy);

return 0;

err:
module_compiler_cleanup();
sepol_sidtab_destroy(&sidtab);
policydb_destroy(&policydb);
policydb_destroy(&parse_policy);
Expand Down
6 changes: 6 additions & 0 deletions checkpolicy/module_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,3 +1492,9 @@ static void pop_stack(void)
free(stack_top);
stack_top = parent;
}

void module_compiler_cleanup()
{
while (stack_top)
pop_stack();
}
2 changes: 2 additions & 0 deletions checkpolicy/module_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ int begin_optional_else(int pass);
* return -1. */
int end_avrule_block(int pass);

void module_compiler_cleanup(void);

#endif

0 comments on commit 6aaff88

Please sign in to comment.