Opened 7 years ago

Closed 3 years ago

#5829 closed defect (wontfix)

[PATCH] Segfault when exiting with open HDF dataset

Reported by: kikht Owned by: warmerdam
Priority: normal Milestone: closed_because_of_github_migration
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords:
Cc:

Description

Attached test program fails with segfault on exit(0); call.

It happens because HDF library sets it's own cleanup procecure via atexit. It is called before GDALDriverManager destructor which tries to close opened hdf file again, leading to segfault.

Provided patch disables HDF cleanup procedure by calling HDdont_atexit() on driver initialization.

Attachments (3)

hdf_test.c (174 bytes) - added by kikht 7 years ago.
Test program
issue5829.patch (395 bytes) - added by kikht 7 years ago.
patch
HEshutdown.patch (381 bytes) - added by kikht 7 years ago.
HDF4 library patch

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by kikht

Attachment: hdf_test.c added

Test program

Changed 7 years ago by kikht

Attachment: issue5829.patch added

patch

comment:1 Changed 7 years ago by Even Rouault

I'm not too sure about what to do with that. The doc of HDdont_atexit() mentions that it prevents the HDF4 lib from freeing its buffers. This could be workaround by directly calling HPend() when unregistering the driver, but we don't know if another piece of code in the process (not GDAL) isn't going to use HDF4 lib again. This is a mess...

The safe side is to make sure you properly close with GDALClose() explicitely, or call GDALDestroyDriverManager() explicitely.

I'm not convinced that introducing a destructor function in GDAL was a good idea. It seems to cause more issues than it solves ones...

comment:2 Changed 7 years ago by kikht

I've also sent patch to hdflib that fixes this issue from their side. Unfortunately they do not have public tracker.

comment:3 Changed 7 years ago by Even Rouault

What is the change you submitted on hdflib side ?

Changed 7 years ago by kikht

Attachment: HEshutdown.patch added

HDF4 library patch

comment:4 Changed 7 years ago by kikht

Attached patch fixes HEshutdown function in HDF4. It frees error_stack and sets it to NULL, but misses to set error_top to 0. Some functions (e.g. HEPclear) rely on error_top value to detect stack existence, so it can lead to null pointer dereference.

The idea is to make HDF cleanup functions idempotent, but this patch fixes the only problem I've noticed.

comment:5 Changed 3 years ago by Even Rouault

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub?. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.