[postgis-devel] Memory alignment issues (was: crash(somehow)resolved)

Michael Fuhr mike at fuhr.org
Thu Nov 17 15:56:55 PST 2005


On Thu, Nov 17, 2005 at 11:51:36PM +0100, strk at refractions.net wrote:
> Michael, if you happen to run gcc, you might try adding
> the -Wcast-align flag. I haven't had an option to test
> it as on my architecture all cast are alignment-safe,
> but sounds interesting.

I'll add that flag on the sparc when I get a chance, but I don't
think the problem is architecture-specific; I get the same crash
on FreeBSD 6.0/i386 with PostgreSQL 8.1.0.  Here's a stack trace
on that platform:

#0  0x284e34b3 in kill () from /lib/libc.so.6
#1  0x284d84f0 in raise () from /lib/libc.so.6
#2  0x28552c5c in abort () from /lib/libc.so.6
#3  0x08216fca in ExceptionalCondition (conditionName=0xcfff <Address 0xcfff out of bounds>, errorType=0x5 <Address 0x5 out of bounds>, fileName=0x0, 
    lineNumber=163) at assert.c:51
#4  0x0822ad6a in MemoryContextDelete (context=0x840201c) at mcxt.c:163
#5  0x0822ae72 in MemoryContextDeleteChildren (context=0x83a4344) at mcxt.c:215
#6  0x0822ad8d in MemoryContextDelete (context=0x83a4344) at mcxt.c:169
#7  0x0813073c in ExecutorEnd (queryDesc=0x837ac48) at execMain.c:283
#8  0x0810b8ae in PortalCleanup (portal=0x83a701c) at portalcmds.c:282
#9  0x0822b97d in PortalDrop (portal=0x83a701c, isTopCommit=0 '\0') at portalmem.c:317
#10 0x081ac8b0 in exec_simple_query (query_string=0x839d01c "select transform(geomfromtext('POINT(0 0)', 4326), 4269);") at postgres.c:1010
#11 0x081ae7fa in PostgresMain (argc=4, argv=0x83263f0, username=0x83263c8 "mfuhr") at postgres.c:3168
#12 0x0818788b in ServerLoop () at postmaster.c:2852
#13 0x08188e51 in PostmasterMain (argc=3, argv=0xbfbfecb8) at postmaster.c:943
#14 0x0814e666 in main (argc=3, argv=0xbfbfecb8) at main.c:256

The crash is due to an assertion in PostgreSQL that's checked only
if the server was built with --enable-cassert.  The code is in
src/backend/utils/mmgr/mcxt.c:

161 MemoryContextDelete(MemoryContext context)
162 {
163     AssertArg(MemoryContextIsValid(context));

For anybody doing server-side development it's probably a good idea
to test on a server built with --enable-cassert; otherwise some
problems might go unnoticed.

-- 
Michael Fuhr



More information about the postgis-devel mailing list