Search Postgresql Archives

Strange memory behaviour with PGreset() ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi folks.  One of my co-workers came to me with a problem.  I took a
look, and it does seem to be a problem.  (But where?  That is why I'm
turning to you...)

The C code below serves as an example.  He is basically trying to
re-connect again to a "bad" database server.  The "server" at
192.168.0.1, port 35000 doesn't exist.

The compile line is:
$ gcc -Wall mem_test.c mem_test -lpq

This test was done on a SuSE 9.2 (or 9.3) machine, and reproduced on a
FC3 machine.

Postgres linked in, is a 7.4.7 on the SuSE machine, 7.4.8 on the FC3
machine.

Is there a bug in the code?  Are we assuming too much about the return
values of PQsetdbLogin?  

Cheers,
--
EinarI@xxxxxxxxxx



======================================CUT HERE============================
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <pwd.h>
#include <pthread.h>
                                                                                                          
#include <libpq-fe.h>

#ifndef TRUE
	#define TRUE 1
#endif

#ifndef FALSE
	#define FALSE 0
#endif

int main(int argc, char **argv, char **envp) {
	int connected;
	PGconn *db_conn = PQsetdbLogin("192.168.0.1", "35000", NULL, NULL, "db", "user", "pass");

	if (db_conn == NULL) {
	    printf("Got NULL back, just quitting...\n");
	    exit(1);
	}

	while (1) {
		switch (PQstatus(db_conn)) {
			case CONNECTION_OK:
				connected = TRUE;
				break;

			case CONNECTION_BAD:
				connected = FALSE;
				break;

			default:
				printf("Unexpected value from PQstatus()!\n");
				exit(1);
				break;
		}

		if (connected == FALSE) {
			printf("Reconnecting\n");
			PQreset(db_conn);
		}
	}

}
======================================CUT HERE============================

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux