Commit 6e545fc8d781e3e4974d9370f5bb3f5bd9fbeef8

Authored by Christian Herdtweck
1 parent 743ad7f4

oleid: ensure olefile is closed

Showing 1 changed file with 7 additions and 0 deletions
oletools/oleid.py
... ... @@ -450,6 +450,10 @@ class OleID(object):
450 450 vba_indicator.risk = RISK.ERROR
451 451 vba_indicator.value = 'Error'
452 452 vba_indicator.description = 'Error while checking VBA macros: %s' % str(e)
  453 + finally:
  454 + if vba_parser is not None:
  455 + vba_parser.close()
  456 + vba_parser = None
453 457 # Check XLM macros only for Excel file types:
454 458 if self.ftg.is_excel():
455 459 # TODO: for now XLM detection only works for files on disk... So we need to reload VBA_Parser from the filename
... ... @@ -465,6 +469,9 @@ class OleID(object):
465 469 xlm_indicator.risk = RISK.ERROR
466 470 xlm_indicator.value = 'Error'
467 471 xlm_indicator.description = 'Error while checking XLM macros: %s' % str(e)
  472 + finally:
  473 + if vba_parser is not None:
  474 + vba_parser.close()
468 475 else:
469 476 xlm_indicator.risk = RISK.UNKNOWN
470 477 xlm_indicator.value = 'Unknown'
... ...