[Gdal-dev] Error opening HDF file

Miguel miguelangel.querol at iver.es
Thu May 31 10:33:58 EDT 2007


Hello,

I have a gdal compilation (release 1.4.0) with HDF4, HDF5 and Grass 
support. I have a test program that opens and closes some HDF4 image 
many times. The problem is when I have an HDF image wich has many 
subdatasets, Gdal crashes when is trying to open the image for the 31st 
time. That's the source code of my test program:

#include <stdio.h>
#include "gdal.h"

int main()
{
   GDALDatasetH  hDataset;
   int i = 0;
   char* file1 = 
"/home/miguel/cd_datos/Modis/MOD11A1.A2006365.h21v07.004.2007002014854.hdf"; 

   char* file2 = 
"/home/miguel/cd_datos/Modis/MYD09Q1.A2006361.h01v08.004.2007009060450.hdf"; 

   char* file3 = 
"/home/miguel/cd_datos/Modis/MOD09Q1.A2006361.h00v08.004.2007006103307.hdf"; 

   int j = 1;

   GDALAllRegister();

     for (i = 0 ; i < 15 ; i++){
       hDataset = GDALOpen( file1 , GA_ReadOnly );
       if( hDataset != NULL ){
           printf("Open image for %d time\n", j);
       j++;
       }
   GDALClose(hDataset);
   }
   for (i = 0 ; i < 15 ; i++){
       hDataset = GDALOpen( file2 , GA_ReadOnly );
       if( hDataset != NULL ){
           printf("Open image for %d time\n", j);
           j++;
       }
       GDALClose(hDataset);
   }
   for (i = 0 ; i < 15 ; i++){
       hDataset = GDALOpen( file3 , GA_ReadOnly );
       if( hDataset != NULL ){
           printf("Open image for %d time\n", j);
           j++;
       }
       GDALClose(hDataset);
   }
}

And that's the error:

...
Open image for 27 time
Open image for 28 time
Open image for 29 time
Open image for 30 time
ERROR 2: CPLMalloc(): Out of memory allocating -4 bytes.

I downlodaded many HDF4 images form the NASA ftp and this problem 
happens in all of them. Is there any limitation in the number of times I 
can open an HDF file with  many subdatasets? Maybe a bug?

Thank you!!
Best regards!

-- 
Miguel Ángel Querol Carratalá
Equipo de desarrollo raster de gvSIG /
gvSIG raster development team.
IVER TI S.A.
C/ Salamanca, 50-52
46005-Valencia
Tlf.963354983  ext. 404
Tlf.+34963163400
www.iver.es
www.gvsig.com





More information about the Gdal-dev mailing list