Skip to content

Commit b2bd47c

Browse files
committed
Free xmlDoc structure at the end of xccdf_session_load
When calling the xccdf_session_load_(xccdf|cpe|oval|tailoring) functions, the session->source structure is recopied to session->ds.session->component_sources, including the source->xml.doc field, which contains the XML DOM. This change adds a new oscap_source_free_xmlDoc function to the OSCAP source API and call it at the end of the xccdf_session_load function, so session->source->xml.doc is freed when it's not used anymore.
1 parent a6d6753 commit b2bd47c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/XCCDF/xccdf_session.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,9 @@ int xccdf_session_load(struct xccdf_session *session)
716716
return ret;
717717
}
718718
}
719-
return xccdf_session_load_tailoring(session);
719+
ret = xccdf_session_load_tailoring(session);
720+
oscap_source_free_xmlDoc(session->source);
721+
return ret;
720722
}
721723

722724
static int _reporter(const char *file, int line, const char *msg, void *arg)

src/source/oscap_source.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ void oscap_source_free(struct oscap_source *source)
153153
}
154154
}
155155

156+
void oscap_source_free_xmlDoc(struct oscap_source *source)
157+
{
158+
if (source != NULL) {
159+
if (source->xml.doc != NULL) {
160+
xmlFreeDoc(source->xml.doc);
161+
source->xml.doc = NULL;
162+
}
163+
}
164+
}
165+
156166
/**
157167
* Returns human readable description of oscap_source origin
158168
*/

src/source/public/oscap_source.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ OSCAP_API struct oscap_source *oscap_source_clone(struct oscap_source *old);
9595
*/
9696
OSCAP_API void oscap_source_free(struct oscap_source *source);
9797

98+
/**
99+
* Dispose oscap_source xmlDoc structure.
100+
* @param source Resource to dispose xmlDoc structure from
101+
*/
102+
OSCAP_API void oscap_source_free_xmlDoc(struct oscap_source *source);
103+
98104
/**
99105
* Get filepath of the given resource
100106
* @memberof oscap_source

0 commit comments

Comments
 (0)