Skip to content

Commit 516a9bd

Browse files
authored
Merge pull request #28 from coiby/covscan_fix_part2
fix RESOURCE_LEAK errors detected by covscan in src/dmidecodemodule.c
2 parents bd25d10 + 1344dc8 commit 516a9bd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/dmidecodemodule.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ xmlNode *__dmidecode_xml_getsection(options *opt, const char *section) {
280280

281281
// Fetch the Mapping XML file
282282
if( (group_n = load_mappingxml(opt)) == NULL) {
283+
xmlFreeNode(dmixml_n);
283284
// Exception already set by calling function
284285
return NULL;
285286
}
@@ -320,7 +321,9 @@ xmlNode *__dmidecode_xml_getsection(options *opt, const char *section) {
320321
if(opt->type == -1) {
321322
char *err = log_retrieve(opt->logdata, LOG_ERR);
322323
log_clear_partial(opt->logdata, LOG_ERR, 0);
323-
PyReturnError(PyExc_RuntimeError, "Invalid type id '%s' -- %s", typeid, err);
324+
_pyReturnError(PyExc_RuntimeError, "Invalid type id '%s' -- %s", typeid, err);
325+
free(err);
326+
return NULL;
324327
}
325328

326329
// Parse the DMI data and put the result into dmixml_n node chain.
@@ -394,6 +397,7 @@ xmlNode *__dmidecode_xml_gettypeid(options *opt, int typeid)
394397

395398
// Fetch the Mapping XML file
396399
if( load_mappingxml(opt) == NULL) {
400+
xmlFreeNode(dmixml_n);
397401
return NULL;
398402
}
399403

@@ -829,8 +833,10 @@ initdmidecodemod(void)
829833
module = Py_InitModule3((char *)"dmidecodemod", DMIDataMethods,
830834
"Python extension module for dmidecode");
831835
#endif
832-
if (module == NULL)
836+
if (module == NULL) {
837+
free(opt);
833838
MODINITERROR;
839+
}
834840

835841
version = PYTEXT_FROMSTRING(VERSION);
836842
Py_INCREF(version);

0 commit comments

Comments
 (0)