Обсуждение: Strange memory behaviour with PGreset() ...

Поиск
Список
Период
Сортировка

Strange memory behaviour with PGreset() ...

От
Einar Indridason
Дата:
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============================

Re: Strange memory behaviour with PGreset() ...

От
Michael Fuhr
Дата:
On Wed, Jul 13, 2005 at 12:09:37PM +0000, Einar Indridason wrote:
>
> 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...)

Your message doesn't say anything about what the problem is -- what
behavior are you expecting or wanting to see, and what behavior are
you actually seeing?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Re: Strange memory behaviour with PGreset() ...

От
Einar Indridason
Дата:
On Wed, Jul 13, 2005 at 07:23:29AM -0600, Michael Fuhr wrote:
> On Wed, Jul 13, 2005 at 12:09:37PM +0000, Einar Indridason wrote:
> >
> > 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...)
>
> Your message doesn't say anything about what the problem is -- what
> behavior are you expecting or wanting to see, and what behavior are
> you actually seeing?

Dem... I knew I had forgotten something :-/

I'm experiencing a memory leak, when I run this program.

Sorry about that.

--
EinarI@f-prot.com

Re: Strange memory behaviour with PGreset() ...

От
Tom Lane
Дата:
Einar Indridason <einari@f-prot.com> writes:
> I'm experiencing a memory leak, when I run this program.

Yup, it's a leak.  See patches just committed at
http://developer.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/libpq/fe-connect.c
(note patch varies depending on branch)

            regards, tom lane