Opened 15 years ago

Closed 15 years ago

#3188 closed defect (fixed)

Leak of layer->items with shapefiles

Reported by: dmorissette Owned by: sdlime
Priority: normal Milestone: 5.6 release
Component: MapServer C Library Version: unspecified
Severity: normal Keywords:
Cc:

Description

Running a simple shp2img on a shapefile layer shows a leak with Valgrind, msShapeFileLayerInitItemInfo() is called twice and the layer->items seems to be overwritten and reallocated without being freed.

==3545== 60 bytes in 1 blocks are definitely lost in loss record 1 of 2
==3545==    at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==3545==    by 0x813A6EF: msDBFGetItemIndexes (mapxbase.c:874)
==3545==    by 0x8138174: msShapeFileLayerInitItemInfo (mapshape.c:2399)
==3545==    by 0x8085A4B: msLayerInitItemInfo (maplayer.c:56)
==3545==    by 0x813898D: msShapeFileLayerGetItems (mapshape.c:2585)
==3545==    by 0x8085FD5: msLayerGetItems (maplayer.c:246)
==3545==    by 0x80864D4: msLayerWhichItems (maplayer.c:385)
==3545==    by 0x808B46E: msDrawVectorLayer (mapdraw.c:926)
==3545==    by 0x808AECC: msDrawLayer (mapdraw.c:809)
==3545==    by 0x8089E6E: msDrawMap (mapdraw.c:455)
==3545==    by 0x8054111: main (shp2img.c:296)

Change History (3)

comment:1 by sdlime, 15 years ago

Status: newassigned

It's the item indexes that aren't being cleaned up I think... I'll take it.

Steve

in reply to:  1 comment:2 by sdlime, 15 years ago

Replying to sdlime:

It's the item indexes that aren't being cleaned up I think... I'll take it.

Steve

The indexes are actually stored in the void iteminfo pointer. Fix might be as simple as this changing msShapeFileLayerInitItemInto() in mapshape.c to:

int msShapeFileLayerInitItemInfo(layerObj *layer)
{
  shapefileObj *shpfile = shpfile = layer->layerinfo;
  if( ! shpfile) {
    msSetError(MS_SHPERR, "Shapefile layer has not been opened.", "msShapeFileLayerInitItemInfo()");
    return MS_FAILURE;
  }

  /* iteminfo needs to be a bit more complex, a list of indexes plus the length of the list */
  msShapeFileLayerFreeItemInfo(layer); /* clean up anything previously allocated */
  layer->iteminfo = (int *) msDBFGetItemIndexes(shpfile->hDBF, layer->items, layer->numitems);
  if( ! layer->iteminfo) {
    return MS_FAILURE;
  }

  return MS_SUCCESS;
}

Would need to do something similar to tiled shapefiles.

Steve

comment:3 by sdlime, 15 years ago

Resolution: fixed
Status: assignedclosed

That was the fix. I updated both the shapefile and tiled shapefile initItemInfo functions to clean up before allocating memory. See r9509...

Steve

Note: See TracTickets for help on using tickets.