Ticket #1540 (assigned defect)

Opened 1 year ago

Last modified 7 months ago

Minor memory leaks in gmlreader.cpp

Reported by: rogerjames99 Assigned to: mloskot (accepted)
Priority: low Milestone: 1.5.3
Component: OGR_SF Version: 1.4.0
Severity: normal Keywords: ogr gml xerces
Cc: warmerdam

Description (Last modified by warmerdam)

I have fixed some minor memory leaks in gmlreader.cpp. The xerces runtime was not being cleaned up properly on exit so I have added a call to XMLPlatformUtils::Terminate(); in the GMLReader class destructor. Also some strings in GMLReader::SetupParser? were not being freed, so I have enclosed them in std::auto_ptr(s). The relevant files modded against the 1.4.0 release are attached. These leaks are trivial but can bite someone making protracted use of the library without reloading.

Attachments

gmlreader.cpp (27.8 kB) - added by rogerjames99 on 03/30/07 07:59:02.
gmlreaderp.h (7.4 kB) - added by rogerjames99 on 03/30/07 07:59:36.
gmlreader-minor-leak-fix.patch (3.0 kB) - added by mloskot on 12/19/07 01:17:47.
This is regular patch including fixes proposed in attached big gmlreaderp.h and gmlreader.cpp files. This patch is to help to review proposed changes.
gml-leaks-new-fix-mloskot.patch (4.0 kB) - added by mloskot on 12/19/07 05:38:23.
This is new improved version of proposed patch. The original version is buggy, because it's forbidden to use std::auto_ptr with buffers allocated by memory manager used in XMLString due to delete / delete[] mismatch.
test.cpp (1.8 kB) - added by mloskot on 12/19/07 06:14:32.
Simple test presenting the proposed patch in action. Running this test result in segmentation fault because internal state of the reader is broken. As Frank predicted, the solution is to track number of XML readers. This test uses road.gml copied to road1.gml and road2.gml. Attached Makefile is used to compile the test.
Makefile (386 bytes) - added by mloskot on 12/19/07 06:14:58.
Makefile used to build test.cpp program
road1.gml (1.3 kB) - added by mloskot on 12/19/07 06:15:39.
Sample GML file. Second copy 'road2.gml' is needed by the test.cpp program.

Change History

03/30/07 07:59:02 changed by rogerjames99

  • attachment gmlreader.cpp added.

03/30/07 07:59:36 changed by rogerjames99

  • attachment gmlreaderp.h added.

03/30/07 15:04:25 changed by warmerdam

  • description changed.
  • cc set to warmerdam.
  • priority changed from lowest to low.
  • version changed from unspecified to 1.4.0.
  • milestone set to 1.5.0.
  • owner changed from warmerdam to mloskot.

Mateusz,

I'd like you to review these changes and apply them if they seem appropriate.

Note, please ensure that the XMLPlatformUtils::Terminate() does not interfere with other GMLReader's that may be active at the same time. So try tests where two GML datastores are open at the same time. Close one, and then verify you can still read from the other.

I suspect the patch will have to be changed to keep track of how many GMLReader's are active, and only call the Terminate() when the last one is destroyed. Presumably that logic should also set m_bXercesInitialized to FALSE.

Since this is low priority and a bit risky as a change, I'd like to hold it to trunk, not the stable branch.

10/19/07 10:42:37 changed by mloskot

  • status changed from new to assigned.

12/19/07 01:17:47 changed by mloskot

  • attachment gmlreader-minor-leak-fix.patch added.

This is regular patch including fixes proposed in attached big gmlreaderp.h and gmlreader.cpp files. This patch is to help to review proposed changes.

12/19/07 05:38:23 changed by mloskot

  • attachment gml-leaks-new-fix-mloskot.patch added.

This is new improved version of proposed patch. The original version is buggy, because it's forbidden to use std::auto_ptr with buffers allocated by memory manager used in XMLString due to delete / delete[] mismatch.

12/19/07 06:14:32 changed by mloskot

  • attachment test.cpp added.

Simple test presenting the proposed patch in action. Running this test result in segmentation fault because internal state of the reader is broken. As Frank predicted, the solution is to track number of XML readers. This test uses road.gml copied to road1.gml and road2.gml. Attached Makefile is used to compile the test.

12/19/07 06:14:58 changed by mloskot

  • attachment Makefile added.

Makefile used to build test.cpp program

12/19/07 06:15:39 changed by mloskot

  • attachment road1.gml added.

Sample GML file. Second copy 'road2.gml' is needed by the test.cpp program.

12/19/07 06:17:28 changed by mloskot

It's important to note that only first run of ./test program throws segmentation fault. Next, .gfs files are available and further executions do not crash.

12/19/07 06:17:37 changed by mloskot

  • keywords changed from ogr gml to ogr gml xerces.

12/19/07 11:05:04 changed by warmerdam

  • milestone changed from 1.5.0 to 1.5.1.

02/05/08 05:44:34 changed by mloskot

  • summary changed from Minor memory leaks in gmlreader.cpp (fixed) to Minor memory leaks in gmlreader.cpp.