|
|
ee1b47 |
From 0cfb9fc93b4cd967c9f8bb2f50df5ccff84a497e Mon Sep 17 00:00:00 2001
|
|
|
ee1b47 |
From: Han Han <hhan@redhat.com>
|
|
|
ee1b47 |
Date: Mon, 9 Apr 2018 15:59:45 +0800
|
|
|
ee1b47 |
Subject: [PATCH] Fix several memory leak in augmatch
|
|
|
ee1b47 |
|
|
|
ee1b47 |
(cherry picked from commit 46a62a71553c6bac8f61ecc2a33f65b13e7ad2c0)
|
|
|
ee1b47 |
---
|
|
|
ee1b47 |
src/augmatch.c | 8 +++++++-
|
|
|
ee1b47 |
1 file changed, 7 insertions(+), 1 deletion(-)
|
|
|
ee1b47 |
|
|
|
ee1b47 |
diff --git a/src/augmatch.c b/src/augmatch.c
|
|
|
ee1b47 |
index 20045c5f..1ac9b680 100644
|
|
|
ee1b47 |
--- a/src/augmatch.c
|
|
|
ee1b47 |
+++ b/src/augmatch.c
|
|
|
ee1b47 |
@@ -131,6 +131,7 @@ static void check_load_error(struct augeas *aug, const char *file) {
|
|
|
ee1b47 |
const char *msg, *line, *col;
|
|
|
ee1b47 |
|
|
|
ee1b47 |
aug_defvar(aug, "info", info);
|
|
|
ee1b47 |
+ free(info);
|
|
|
ee1b47 |
die(aug_ns_count(aug, "info") == 0, "file %s does not exist\n", file);
|
|
|
ee1b47 |
|
|
|
ee1b47 |
aug_defvar(aug, "error", "$info/error");
|
|
|
ee1b47 |
@@ -240,7 +241,7 @@ static void print_tree(struct augeas *aug, int level,
|
|
|
ee1b47 |
static void print(struct augeas *aug, const char *path, const char *match) {
|
|
|
ee1b47 |
static const char *const match_var = "match";
|
|
|
ee1b47 |
|
|
|
ee1b47 |
- cleanup(freep) struct node *nodes = NULL;
|
|
|
ee1b47 |
+ struct node *nodes = NULL;
|
|
|
ee1b47 |
|
|
|
ee1b47 |
nodes = calloc(max_nodes, sizeof(struct node));
|
|
|
ee1b47 |
oom_when(nodes == NULL);
|
|
|
ee1b47 |
@@ -265,6 +266,10 @@ static void print(struct augeas *aug, const char *path, const char *match) {
|
|
|
ee1b47 |
aug_defvar(aug, nodes[0].var, prefix);
|
|
|
ee1b47 |
print_tree(aug, 0, prefix + strlen(path) + 1, nodes);
|
|
|
ee1b47 |
}
|
|
|
ee1b47 |
+ for (int i=0; i < max_nodes; i++) {
|
|
|
ee1b47 |
+ free(nodes[i].var);
|
|
|
ee1b47 |
+ }
|
|
|
ee1b47 |
+ free(nodes);
|
|
|
ee1b47 |
}
|
|
|
ee1b47 |
|
|
|
ee1b47 |
/* Look at the filename and try to guess based on the extension. The
|
|
|
ee1b47 |
@@ -421,6 +426,7 @@ int main(int argc, char **argv) {
|
|
|
ee1b47 |
}
|
|
|
ee1b47 |
|
|
|
ee1b47 |
print(aug, path, match);
|
|
|
ee1b47 |
+ free(path);
|
|
|
ee1b47 |
}
|
|
|
ee1b47 |
|
|
|
ee1b47 |
/*
|
|
|
ee1b47 |
--
|
|
|
ee1b47 |
2.17.2
|
|
|
ee1b47 |
|