Thread: BUG #5731: postmaster sometimes dumps core when handling local connections

BUG #5731: postmaster sometimes dumps core when handling local connections

From
"Alexander V. Chernikov"
Date:
The following bug has been logged online:

Bug reference:      5731
Logged by:          Alexander V. Chernikov
Email address:      melifaro@ipfw.ru
PostgreSQL version: 8.4.5
Operating system:   FreeBSD 7.3
Description:        postmaster sometimes dumps core when handling local
connections
Details:

aluminium# gdb `which postgres` postgres.core

GNU gdb 6.1.1 [FreeBSD]



Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
Core was generated by `postgres'.
Program terminated with signal 11, Segmentation fault.
.....
#0  0x0000000000638f1a in ConnCreate (serverFd=4) at postmaster.c:1939

1939            port->gss = (pg_gssinfo *) calloc(1, sizeof(pg_gssinfo));
(gdb) bt
#0  0x0000000000638f1a in ConnCreate (serverFd=4) at postmaster.c:1939
#1  0x0000000000637f88 in ServerLoop () at postmaster.c:1384
#2  0x000000000063777b in PostmasterMain (argc=3, argv=0x7fffffffec00) at
postmaster.c:1040
#3  0x00000000005c06da in main (argc=3, argv=0x7fffffffec00) at main.c:188
(gdb) p port
$1 = (Port *) 0x0


This simple patch seem to fix the problem

--- src/backend/postmaster/postmaster.c.orig    2010-10-27
19:07:42.000000000 +0400
+++ src/backend/postmaster/postmaster.c 2010-10-27 19:08:25.000000000 +0400
@@ -1917,7 +1917,7 @@
                if (port->sock >= 0)
                        StreamClose(port->sock);
                ConnFree(port);
-               port = NULL;
+               return NULL;
        }
        else
        {

Re: BUG #5731: postmaster sometimes dumps core when handling local connections

From
Heikki Linnakangas
Date:
On 27.10.2010 18:19, Alexander V. Chernikov wrote:
> Program terminated with signal 11, Segmentation fault.
> .....
> #0  0x0000000000638f1a in ConnCreate (serverFd=4) at postmaster.c:1939
>
> 1939            port->gss = (pg_gssinfo *) calloc(1, sizeof(pg_gssinfo));

Hmm, so you get a crash whenever accept() or one of the other calls in
StreamConnection fails, and the server is compiled with GSSAPI. Funny
that it has gone unnoticed for such a long time, clearly accept() and
friends don't fail very often.

> This simple patch seem to fix the problem

Thanks, patch applied.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com