Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#1802 closed defect (fixed)

Leak of shapefile handles

Reported by: dmorissette Owned by: dmorissette
Priority: high Milestone:
Component: MapServer C Library Version: 4.8
Severity: normal Keywords: VERIFIED
Cc:

Description

We have found that mapshape.c can leak file handles when using tileindexes on
shapefile layers.

This leak is very hard to reproduce, it happens only when rendering a map on a
tiled shapefile layer in which some tiles match the current map extents, but the
actual shapefile for that given tile does not contain any shape in the current
map extent, this can happen when hitting the corner of a tile for instance.

What happens is that msTiledSHPWhichShapes() has a loop to "position the source
at the FIRST shapefile" that tries to open tiles until it reaches one that
contains visible shapes. If the call to msSHPWhichShapes() for a given tile
returns MS_DONE, then we were just continuing the loop without closing the open
file, resulting in a leaked file handle (leaks of all three shp, shx and dbf
handles).

The fix is simple:

--- mapshape.c  15 May 2006 19:11:29 -0000      1.69.2.1
+++ mapshape.c  14 Jun 2006 12:26:23 -0000
@@ -1732,7 +1732,11 @@
 #endif
  
         status = msSHPWhichShapes(tSHP->shpfile, rect, layer->debug);
-        if(status == MS_DONE) continue; /* next tile */
+        if(status == MS_DONE) {
+            /* Close and continue to next tile */
+            msSHPCloseFile(tSHP->shpfile);
+            continue;
+        }
         else if(status != MS_SUCCESS) return(MS_FAILURE);
  
         tSHP->tileshpfile->lastshape = i;

Change History (3)

comment:1 by dmorissette, 18 years ago

Resolution: fixed
Status: newclosed
Fixed in CVS in both 4.8.x (will be in 4.8.4) and 4.9 dev.

Note that in the 4.9 version I also took the liberty of closing the file in case
of errors:

diff -r1.70 mapshape.c
1736,1737c1736,1744
<         if(status == MS_DONE) continue; /* next tile */
<         else if(status != MS_SUCCESS) return(MS_FAILURE);
---
>         if(status == MS_DONE) {
>             /* Close and continue to next tile */
>             msSHPCloseFile(tSHP->shpfile);
>             continue;
>         }
>         else if(status != MS_SUCCESS) {
>             msSHPCloseFile(tSHP->shpfile);
>             return(MS_FAILURE);
>         }

comment:2 by dmorissette, 18 years ago

There were 3 more instances of the same leak pattern in mapshape.c. I have fixed
them in CVS in both 4.8.x (will be in 4.8.4) and 4.9 dev.


comment:3 by dmorissette, 18 years ago

Keywords: VERIFIED added
Note: See TracTickets for help on using tickets.