[GRASS-dev] [GRASS GIS] #468: crash in GPJ_grass_to_wkt() on windows

#468: crash in GPJ_grass_to_wkt() on windows
-------------------------+--------------------------------------------------
Reporter: jef | Owner: grass-dev@lists.osgeo.org
     Type: defect | Status: new
Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Keywords: | Platform: MSWindows XP
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
QGIS crashes when calling GPJ_grass_to_wkt(), when the MinGW built
libraries are called from MSVC build QGIS. This is caused to using
G_free() on a string alloced in proj.4 with pj_malloc(). The attached
patch free the string with pj_dalloc()

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/468&gt;
GRASS GIS <http://grass.osgeo.org>

#468: crash in GPJ_grass_to_wkt() on windows
---------------------------+------------------------------------------------
  Reporter: jef | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords:
  Platform: MSWindows XP | Cpu: Unspecified
---------------------------+------------------------------------------------
Comment (by neteler):

The definition of pj_dalloc() is here:
http://svn.osgeo.org/metacrs/proj/trunk/proj/src/pj_malloc.c

{{{
void
pj_dalloc(void *ptr) {
         free(ptr);
}
}}}

The definition of G_free() is here:
http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/lib/gis/alloc.c#L127

{{{
void G_free(void *buf)
{
     free(buf);
}
}}}

Is there a difference?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/468#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#468: crash in GPJ_grass_to_wkt() on windows
---------------------------+------------------------------------------------
  Reporter: jef | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords:
  Platform: MSWindows XP | Cpu: Unspecified
---------------------------+------------------------------------------------
Comment (by jef):

Replying to [comment:1 neteler]:
> The definition of pj_dalloc() is here:
> http://svn.osgeo.org/metacrs/proj/trunk/proj/src/pj_malloc.c
>
> {{{
> void
> pj_dalloc(void *ptr) {
> free(ptr);
> }
> }}}
>
> The definition of G_free() is here:
>
http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/lib/gis/alloc.c#L127
>
> {{{
> void G_free(void *buf)
> {
> free(buf);
> }
> }}}
>
> Is there a difference?

sure. Every DLL runs it own memory management and therefore memory
malloc() in a one DLL needs to be free by the very same DLL and that's
probably the sole reason for the existance of above functions (same for
GDAL, GEOS...).

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/468#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#468: crash in GPJ_grass_to_wkt() on windows
---------------------------+------------------------------------------------
  Reporter: jef | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords:
  Platform: MSWindows XP | Cpu: Unspecified
---------------------------+------------------------------------------------
Comment (by jef):

Replying to [comment:2 jef]:

> sure. Every DLL runs it own memory management and therefore memory
malloc() in a one DLL needs to be free by the very same DLL and that's
probably the sole reason for the existance of above functions (same for
GDAL, GEOS...).

Did you also have a dejavu? :wink: http://trac.osgeo.org/gdal/ticket/1983

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/468#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#468: crash in GPJ_grass_to_wkt() on windows
---------------------------+------------------------------------------------
  Reporter: jef | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: new
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: | Keywords:
  Platform: MSWindows XP | Cpu: Unspecified
---------------------------+------------------------------------------------
Comment (by pkelly):

I fixed this in TRUNK, and fixed a few memory leaks at the same time. The
changes are too complicated/risky to backport to 6.x though, so the simple
patch attached here should be OK for a quick fix.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/468#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#468: crash in GPJ_grass_to_wkt() on windows
---------------------------+------------------------------------------------
  Reporter: jef | Owner: grass-dev@lists.osgeo.org
      Type: defect | Status: closed
  Priority: major | Milestone: 6.4.0
Component: default | Version: unspecified
Resolution: fixed | Keywords:
  Platform: MSWindows XP | Cpu: Unspecified
---------------------------+------------------------------------------------
Changes (by neteler):

  * status: new => closed
  * resolution: => fixed

Comment:

jef's patch applied to 6.4.svn (r35668) and 6.4.0svn (r35669).

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/468#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>