Strange memory behaviour with PGreset() ... - Mailing list pgsql-general

From Einar Indridason
Subject Strange memory behaviour with PGreset() ...
Date
Msg-id 20050713120937.GJ2400@f-prot.com
Whole thread Raw
Responses Re: Strange memory behaviour with PGreset() ...
List 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@f-prot.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============================

pgsql-general by date:

Previous
From: David Pratt
Date:
Subject: Array as parameter for plpgsql function
Next
From: Roman Neuhauser
Date:
Subject: Re: 7.4.7: strange planner decision