[PATCH 1/5] Clear memory allocated for event names
Lubomir I. Ivanov
neolit123 at gmail.com
Sun Dec 23 17:51:39 PST 2012
From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
parse-xml.c:
When parsing events, we allocate memory for the event 'name' attribute,
but also have to free this memory eventually. Let's do that in event_end()
right after add_event() is called.
Fixes a long-running memory leak in the parser.
Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
parse-xml.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/parse-xml.c b/parse-xml.c
index 57c4dd1..f68474a 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1050,10 +1050,13 @@ static struct divecomputer *get_dc(void)
static void event_end(void)
{
struct divecomputer *dc = get_dc();
- if (cur_event.name && strcmp(cur_event.name, "surface") != 0)
- add_event(dc, cur_event.time.seconds,
- cur_event.type, cur_event.flags,
- cur_event.value, cur_event.name);
+ if (cur_event.name) {
+ if (strcmp(cur_event.name, "surface") != 0)
+ add_event(dc, cur_event.time.seconds,
+ cur_event.type, cur_event.flags,
+ cur_event.value, cur_event.name);
+ free((void *)cur_event.name);
+ }
cur_event.active = 0;
}
--
1.7.11.msysgit.0
More information about the subsurface
mailing list