[postgis-devel] C-Library function returning PostGIS point crashing backend

David Fuhry dfuhry at gmail.com
Fri Jan 18 10:47:31 PST 2013


Dropping the lwgeom_init_allocators function doesn't work because CREATE
FUNCTION then fails with error:
ERROR:  could not load library "/usr/local/pgsql/lib/test2.so":
/usr/local/pgsql/lib/test2.so: undefined symbol: lwgeom_init_allocators

Declaring an empty lwgeom_init_allocators doesn't work because an infinite
loop seems to occur where lwgeom_init_allocators is repeatedly called (I
think).

What did work was imitating libpgcommon/lwgeom_pg.c and defining my own
pg_alloc etc., then having lwgeom_init_allocators assign lwalloc_var =
pg_alloc; and likewise for the others. strk I think you were right about
allocation using malloc and deallocation using pfree because the
implementation of lwgeom_install_default_allocators (in lwutil.c)
sets lwalloc_var = default_allocator; and default_allocator uses malloc.

Thanks for the help, all. Working code is attached.

-Dave




On Tue, Jan 15, 2013 at 3:04 AM, Sandro Santilli <strk at keybit.net> wrote:

> On Mon, Jan 14, 2013 at 10:19:52PM -0500, David Fuhry wrote:
> > Not sure if this reveals anything more, but here's the valgrind output.
> > Apparently the segfault is of reading 16 bytes before the memory location
> > malloced in lwgeom_to_wkb, I don't know if that's a coincidence or not.
>
> 16 bytes could the the amount of bytes used for postgresql memory
> management functions, so it could really be that postgis is allocating
> with malloc and deallocating with pfree, pointing back to liblwgeom
> memory initialization functions.
> Try to drop the memory management initialization function and see
> what happens. Or try to get liblwgeom initialized with your own
> management functions and see how/when they are called.
>
> --strk;
> _______________________________________________
> postgis-devel mailing list
> postgis-devel at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20130118/7333d5eb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.c
Type: text/x-csrc
Size: 1539 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20130118/7333d5eb/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 287 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20130118/7333d5eb/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.sql
Type: application/octet-stream
Size: 113 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20130118/7333d5eb/attachment-0001.obj>


More information about the postgis-devel mailing list