I've found perhaps a bug.
I've narrowed down my code and the problem is indeed at: conn = PQconnectdb(conninfo);
My connection string: host=192.168.178.12 dbname=DATABASE user=foo password=barI've narrowed down my code and the problem is indeed at: conn = PQconnectdb(conninfo);
==9195==
==9195== HEAP SUMMARY:
==9195== in use at exit: 450,080 bytes in 2,829 blocks
==9195== total heap usage: 9,476 allocs, 6,647 frees, 7,810,733 bytes allocated
==9195==
==9195== LEAK SUMMARY:
==9195== definitely lost: 0 bytes in 0 blocks
==9195== indirectly lost: 0 bytes in 0 blocks
==9195== possibly lost: 0 bytes in 0 blocks
==9195== still reachable: 450,080 bytes in 2,829 blocks
==9195== suppressed: 0 bytes in 0 blocks
==9195== Rerun with --leak-check=full to see details of leaked memory
==9195==
==9195== For counts of detected and suppressed errors, rerun with: -v
==9195== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 14 from 6)
Played with hostaddr as well and gave me the same result.
http://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-PQCONNECTDB
http://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-PARAMKEYWORDS
"PostgreSQL 9.4.4 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.7.2-5) 4.7.2, 64-bit"
The attachment is the program I've used for testing.
2015-07-18 0:15 GMT+02:00 Tom Lane <tgl@xxxxxxxxxxxxx>:
Peter Kroon <plakroon@xxxxxxxxx> writes:
> Every now and then my program will abort.
> IAnd this is because: conn = PQconnectdb(conninfo);
> The error given:
> *** Error in `./server_prog': malloc(): smallbin double linked list
> corrupted: 0x092c10a0 ***
This looks like malloc() complaining because something has corrupted its
bookkeeping data, which generally means that something previously wrote
past the end of a malloc'd data chunk, or tried to write into an
already-freed chunk. The odds are very high that the bug is in your
program rather than libpq, though, because no such problems have been
found within libpq recently.
valgrind is a fairly useful tool for tracking down such issues.
regards, tom lane
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include "/usr/include/postgresql/libpq-fe.h" static void exit_nicely(PGconn *conn) { PQfinish(conn); exit(1); } void *print_message_function( void *ptr ); main() { int MAX = 10; pthread_t thread[MAX]; const char *message = "Hello Wordl!"; int iret[MAX]; /* Create independent threads each of which will execute function */ int i; for ( i = 0; i < MAX; i++ ) { iret[i] = pthread_create( &thread[i], NULL, print_message_function, (void*) message); if(iret[i]) { fprintf(stderr,"Error, return code: %d\n", iret[i]); exit(EXIT_FAILURE); } } for ( i = 0; i < MAX; i++ ) printf("pthread_create(), thread %d returns: %d\n", i, iret[i]); for ( i = 0; i < MAX; i++ ) pthread_join( thread[i], NULL); exit(EXIT_SUCCESS); } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); // database variable const char *conninfo; PGconn *conn; PGresult *res; int nFields, nRows; int i, j; int result_ok = 0; conninfo = "host=127.0.0.1 dbname=postgres user=postgres password=XXX port=5432"; /* Make a connection to the database */ conn = PQconnectdb(conninfo); /* Check to see that the backend connection was successfully made */ if (PQstatus(conn) != CONNECTION_OK) { fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(conn)); exit_nicely(conn); } /* Start a transaction block */ res = PQexec(conn, "BEGIN"); PQclear(res); /* disable notice */ res = PQexec(conn, "SET client_min_messages TO NOTICE;"); PQclear(res); /* end the transaction */ res = PQexec(conn, "END"); PQclear(res); /* close the connection to the database and clean-up */ PQfinish(conn); }
-- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general