Strange memory behaviour with PGreset() ...

From: Einar Indridason <einari(at)f-prot(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Strange memory behaviour with PGreset() ...
Date: 2005-07-13 12:09:37
Message-ID: 20050713120937.GJ2400@f-prot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(at)f-prot(dot)com

======================================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============================

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Roman Neuhauser 2005-07-13 12:48:27 Re: 7.4.7: strange planner decision
Previous Message David Pratt 2005-07-13 12:00:47 Array as parameter for plpgsql function