Hello

I have some problem with memory leak using postgres 6.5 (?) on debian linux 2.1.
I have writen following C program:

#include "libpq-fe.h"
#include <stdio.h>
#include <time.h>

PGconn* db;
char d[1001];
char c[5000];
signed long r1,r2,r3,r4,r5;
int i,p,q;
PGresult* dbout;

unsigned long er (unsigned long from,unsigned long to)
{return (from+(to-from)*(float)rand()/RAND_MAX);};

int genchr (void)
{do {p=(int)(40+82*(float)rand()/RAND_MAX);}
 while (((p>41)&&(p<48))||((p>58)&&(p<65))||((p>90)&&(p<97)));
 return (p);};

void main ()
{db = PQsetdb ("127.0.0.1","1111","","","Ttts");
 for (q=1;q<1000;q++)
 {
  r1 = er (1,30);
  for (i=1;i<=r1;i++) {d[i-1]=genchr();};
  d[r1]='\0';
  sprintf (c,"select * from t1 where lower(c) ~~ lower ('%%%s%%') order by n1",d);
  dbout = PQexec (db,"BEGIN");
  PQclear (dbout);
  dbout = PQexec (db,c);
  PQclear (dbout);        
  dbout = PQexec (db,"END");
  PQclear (dbout);
 };
 PQfinish (db);
}

This program generates querys into db. This program is compiled with following 
settings:

gcc test.c -I /usr/include/postgresql -lpq -lcrypt -o test -Wall

Then I run postmaster (from postgres account):

./postmaster -i -p 1111 -D /var/postgres/data/

Then i run top and see that in system is 223308Kb of memory free, then i run test ... 
after test ends top indicates 103328Kb free, then i end the postmaster with CTRL C, 
top indicates 104132Kb free, then i end top disconnect from all consoles and again 
connect and run top the number is unchanged (+-50Kb).
After reboot i have try it again, with the same result. I supposed that it is cache, 
but when i then start some stupid program which only want to allocate 200000Kb this 
program fail on not enought memory. For this reason i think that it is not cache. But 
what is it then???

Where i'm making a mystake ???

Thanks for help.
                                Ice Planet 
e-mail: [EMAIL PROTECTED]

Reply via email to