Summary:ASTERISK-02133: Remove the cdr_pgsql.conf + Asterisk reload = Crash (Segmentation fault)
Reporter:Belaid Arezqui (areski)Labels:
Date Opened:2004-07-28 12:17:35Date Closed:2008-01-15 15:03:46.000-0600
Versions:Frequency of
Environment:Attachments:( 0) cdr_pgsql.c.patch.txt
Description:I was testing the RC1 and also the cdr pgsql to see if it was working correctly.
I setup cdr_pgsql.conf reload my asterisk.

All cdr_psql work well, but then I decided to delete the line I have been add in cdr_pgsql.conf... Then I "reloaded" asterisk again and crash !!!
Segmentation fault

(gdb) bt
#0  0x42082a15 in memcpy () from /lib/i686/libc.so.6
#1  0x41ac891b in pqPutBytes () from /usr/lib/libpq.so.2
#2  0x41ac87b8 in pqPutc () from /usr/lib/libpq.so.2
#3  0x41ac50bc in closePGconn () from /usr/lib/libpq.so.2
#4  0x41ac5167 in PQfinish () from /usr/lib/libpq.so.2
ASTERISK-1  0x41ab4810 in my_unload_module () at cdr_pgsql.c:145
ASTERISK-2  0x41ab506b in reload () at cdr_pgsql.c:321
ASTERISK-3  0x08055920 in ast_module_reload ()
ASTERISK-4  0x08071c56 in handle_reload ()
ASTERISK-5  0x08073966 in ast_cli_command ()
ASTERISK-6 0x0808525b in consolehandler ()
ASTERISK-7 0x08087ce6 in main ()
ASTERISK-8 0x42017589 in __libc_start_main () from /lib/i686/libc.so.6

It happens always, if not at the first reload at the second...

Hope its help, Good luck


Red Hat GNU/Linux 7.3b (Mystic)
operating system release : 2.4.20-24.7

Show version:
Asterisk 1.0-RC1 built by machbuild@python2 on a i686 running Linux
Comments:By: Mark Spencer (markster) 2004-07-28 13:59:44

Find me on IRC and I'll take a look.

By: Mark Spencer (markster) 2004-07-28 14:56:45

Also I've made a change in CVS, please let me know if that fixes it.

By: Tilghman Lesher (tilghman) 2004-07-29 01:06:12

Are you using the most current version of libpq?  If not, could you download and install Postgres from www.postgresql.org and see if you can replicate this problem?

By: Rob Gagnon (rgagnon) 2004-07-29 02:40:59

Odd... Looking at the code, it appears to be a bug somehow within the libpq.so library.

The line in asterisk source is this:

static int my_unload_module(void)
  if (conn)
  conn = NULL;

Which is perfectly safe.   I don't see how the missing config file would make a problem.

What line did you add/remove from the .conf file?

Also, I do see a small problem in my_load_module(), however:

The section:
  var = ast_variable_browse(cfg, "global");
  if (!var) {
     /* nothing configured */
     return 0;

is missing "ast_destroy(cfg);" before the return.  In fact, they are missing all over the my_load_module() code....

Gimme a minute to make a patch..

By: Rob Gagnon (rgagnon) 2004-07-29 02:47:16

nevermind the first 2 patches.   it turns out I accidentally used my local cdr_pgsql.c instead of original cvs copy....  please delete them.

The last one with "(1,567 bytes) 07-29-04 02:52" is the one I meant to put there...

It fixes what would be a memory leak if the [global] section is missing

edited on: 07-29-04 02:37

By: Belaid Arezqui (areski) 2004-07-29 05:12:16

I have tested the last CVS version but this time on Fedora 2... same problem (alsmost)!

(gdb) bt
#0  0x00ccd147 in resetPQExpBuffer () from /usr/lib/libpq.so.3
#1  0x00ccd1ff in printfPQExpBuffer () from /usr/lib/libpq.so.3
#2  0x00cc6cb7 in pqReadData () from /usr/lib/libpq.so.3
#3  0x00cc6d69 in pqFlush () from /usr/lib/libpq.so.3
#4  0x00cc1fb6 in PQconnectPoll () from /usr/lib/libpq.so.3
ASTERISK-1  0x00cc1fd8 in PQfinish () from /usr/lib/libpq.so.3
ASTERISK-2  0x0040ad72 in my_unload_module () at cdr_pgsql.c:151
ASTERISK-3  0x0040acfb in reload () at cdr_pgsql.c:322
ASTERISK-4  0x08056232 in ast_module_reload () at loader.c:170
ASTERISK-5  0x0806ed1a in handle_reload (fd=1, argc=1, argv=0xfeeffcb0) at cli.c:106
ASTERISK-6 0x0806eb08 in ast_cli_command (fd=1, s=0x60 "") at cli.c:1019
ASTERISK-7 0x08086356 in main (argc=139928576, argv=0xfeeffe0c) at asterisk.c:619

To the question which line I am removing :
I have that when I start asterisk

-- ALL works great !
Then I comment as below

AND the problem appears : Seg fault :/

By: Belaid Arezqui (areski) 2004-07-29 06:59:10

Sorry it seems I am too dump to get correctly the lastest CVS :/

NOW, it works correctly with
static int my_unload_module(void)
       if (conn)
       conn = NULL;

Thanks :)

By: Digium Subversion (svnbot) 2008-01-15 15:03:46.000-0600

Repository: asterisk
Revision: 3528

U   trunk/cdr/cdr_pgsql.c

r3528 | markster | 2008-01-15 15:03:45 -0600 (Tue, 15 Jan 2008) | 2 lines

Only Call PQfinish if conn isn't NULL (bug ASTERISK-2133)