Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#1576 closed defect (fixed)

Crash during destruction of shapefile datasources without spatial references

Reported by: Kosta Owned by: Mateusz Łoskot
Priority: normal Milestone: 1.5.0
Component: OGR_SRS Version: unspecified
Severity: major Keywords:
Cc: warmerdam

Description

During the destruction of a OGRShapeLayer object without a valid spatial reference object (poSRS == NULL) a NULL pointer exception is generated when calling "poSRS->Release()".

In OGRFeatureDefn::Release() this case is handled by testing for "this != NULL". The same test should be added to OGRSpatialReference::Release():

Index: ogrspatialreference.cpp
===================================================================
--- ogrspatialreference.cpp	(revision 11280)
+++ ogrspatialreference.cpp	(working copy)
@@ -290,7 +290,7 @@
 void OGRSpatialReference::Release()
 
 {
-    if( Dereference() <= 0 )
+    if( this && Dereference() <= 0 )
         delete this;
 }

Change History (8)

comment:1 by Kosta, 17 years ago

Priority: normalhigh

comment:2 by warmerdam, 17 years ago

Cc: warmerdam added
Milestone: 1.5.0
Owner: changed from warmerdam to Mateusz Łoskot
Priority: highnormal

Mateusz,

I understand you have already re-added the "this" test to the OGRSpatialReference Release method. But it is really an error in calling code to invoke Release on a NULL pointer. So I would like you to:

  • Add an assertion in OGRSpatialReference::Release() that this is not NULL.
  • Track down the original problem in the shapefile driver so this doesn't occur.

It is sufficient to do this cleanup in trunk.

Thanks...

comment:3 by Kosta, 17 years ago

But then the same behavior should be implemented for OGRFeatureDefn::Release()!

comment:4 by Mateusz Łoskot, 17 years ago

Status: newassigned

comment:5 by Mateusz Łoskot, 17 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r11294. Both Frank's and Kosta's suggestions have been applied.

comment:6 by Kosta, 17 years ago

A related ticket can be found here: #738

comment:7 by Mateusz Łoskot, 17 years ago

Kosta,

Please, confirm if the fix works for you. Thank you!

comment:8 by Kosta, 17 years ago

OK, fixed, thx ... :-)

Note: See TracTickets for help on using tickets.