From 3d26d2431c584c327be741491684361ca1799fd5 Mon Sep 17 00:00:00 2001 From: Steve Beattie Date: Mon, 14 Oct 2013 14:34:12 -0700 Subject: [PATCH] parser - fix more memory leaks This patch fixes a few more parser memory leaks as identified by the simple valgrind test script. These mostly occur during cleanup of structs and classes and as such, don't represent very serious leaks for common usages of the parser. Signed-off-by: Steve Beattie Acked-by: John Johansen --- parser/parser_lex.l | 8 +++++--- parser/parser_misc.c | 5 +++++ parser/profile.cc | 7 ++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/parser/parser_lex.l b/parser/parser_lex.l index 7093759dc..9fca6ad09 100644 --- a/parser/parser_lex.l +++ b/parser/parser_lex.l @@ -1,8 +1,8 @@ /* * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 * NOVELL (All rights reserved) - * Copyright (c) 2010 - 2012 - * Canonical Ltd. + * Copyright (c) 2010 - 2013 + * Canonical Ltd. (All rights reserved) * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -167,8 +167,10 @@ static int include_dir_cb(__unused DIR *dir, const char *name, struct stat *st, if (asprintf(&path, "%s/%s", d->fullpath, name) < 0) yyerror("Out of memory"); - if (is_blacklisted(name, path)) + if (is_blacklisted(name, path)) { + free(path); return 0; + } if (S_ISREG(st->st_mode)) { if (!(yyin = fopen(path,"r"))) diff --git a/parser/parser_misc.c b/parser/parser_misc.c index f3251ab96..2b819796d 100644 --- a/parser/parser_misc.c +++ b/parser/parser_misc.c @@ -2,6 +2,9 @@ * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 * NOVELL (All rights reserved) * + * Copyright (c) 2013 + * Canonical Ltd. (All rights reserved) + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License published by the Free Software Foundation. @@ -874,6 +877,8 @@ void free_cod_entries(struct cod_entry *list) free(list->name); if (list->link_name) free(list->link_name); + if (list->nt_name) + free(list->nt_name); if (list->pat.regex) free(list->pat.regex); free(list); diff --git a/parser/profile.cc b/parser/profile.cc index 0914a53ea..62da9939d 100644 --- a/parser/profile.cc +++ b/parser/profile.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 + * Copyright (c) 2012, 2013 * Canonical, Ltd. (All rights reserved) * * This program is free software; you can redistribute it and/or @@ -72,12 +72,17 @@ Profile::~Profile() aare_delete_ruleset(policy.rules); if (policy.dfa) free(policy.dfa); + if (xmatch) + free(xmatch); if (name) free(name); if (attachment) free(attachment); if (ns) free(ns); + for (int i = (AA_EXEC_LOCAL >> 10) + 1; i < AA_EXEC_COUNT; i++) + if (exec_table[i]) + free(exec_table[i]); if (net.allow) free(net.allow); if (net.audit)