# Buggy code
def StoreReport(self, analysis_report):
    """Store an analysis report.

    Args:
      analysis_report: An analysis report object (instance of AnalysisReport).
    """
    report_number = 1
    for name in self._GetStreamNames():
        if name.startswith("plaso_report."):
            _, _, number_string = name.partition(".")
            try:
                number = int(number_string, 10)
            except ValueError:
                logging.error("Unable to read in report number.")
                number = 0
            if number >= report_number:
                report_number = number + 1

    stream_name = "plaso_report.{0:06}".format(report_number)

    if self._serializers_profiler:
        self._serializers_profiler.StartTiming("analysis_report")

    serialized_report_proto = self._analysis_report_serializer.WriteSerialized(
        analysis_report
    )

    if self._serializers_profiler:
        self._serializers_profiler.StopTiming("analysis_report")

    self._WriteStream(stream_name, serialized_report_proto)


# Traceback (MemoryError)
2015-10-14 12:58:53,921 [WARNING] (StorageWriter) PID:2384 <multi_process> Unhandled exception in storage writer (PID: 2384).
2015-10-14 12:58:53,926 [ERROR] (StorageWriter) PID:2384 <multi_process>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/plaso/multi_processing/multi_process.py", line 1184, in _Main
self._storage_writer.WriteEventObjects()
File "/usr/lib/python2.7/dist-packages/plaso/lib/storage.py", line 1645, in WriteEventObjects
self._Close()
File "/usr/lib/python2.7/dist-packages/plaso/lib/storage.py", line 1675, in _Close
self._storage_file.Close()
File "/usr/lib/python2.7/dist-packages/plaso/lib/storage.py", line 874, in Close
self._FlushBuffer()
File "/usr/lib/python2.7/dist-packages/plaso/lib/storage.py", line 431, in _FlushBuffer
self._WriteStream(stream_name, b''.join(proto_str))
MemoryError
2015-10-14 12:59:17,026 [WARNING] (MainProcess) PID:2379 <multi_process> Killing process: Worker_00 (PID: 2385).
2015-10-14 12:59:17,026 [WARNING] (MainProcess) PID:2379 <multi_process> Killing process: Worker_04 (PID: 2392).
Processing completed with errors.

# Fixed code
def StoreReport(self, analysis_report):
    """Store an analysis report.

    Args:
      analysis_report: an analysis report object (instance of AnalysisReport).
    """
    report_number = 1
    for name in self._GetStreamNames():
        if name.startswith("plaso_report."):
            _, _, number_string = name.partition(".")
            try:
                number = int(number_string, 10)
            except ValueError:
                logging.error("Unable to read in report number.")
                number = 0
            if number >= report_number:
                report_number = number + 1

    stream_name = "plaso_report.{0:06}".format(report_number)

    if self._serializers_profiler:
        self._serializers_profiler.StartTiming("analysis_report")

    serialized_report_proto = self._analysis_report_serializer.WriteSerialized(
        analysis_report
    )

    if self._serializers_profiler:
        self._serializers_profiler.StopTiming("analysis_report")

    self._WriteStream(stream_name, serialized_report_proto)