Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a5529f

Browse files
committed
From: Igor <igor@sba.miami.edu>
Subject: [PATCHES] memory leak patches in libpq and psqlA couple of small memory leak patches (detected with Purify) primarilyin libpq.* Fixed (NULL) border problem in psql (run psql, do \m, then select something from a table...row separators will be nulls)* Fixed memory leak with the abovementioned border not being freed properly.* Fixed memory leak in freePGconn() not freeing conn->port* Fixed up PQclear() to free parts of PGresult only if these parts are not null.* Fixed a decent memory leak that occured after executing every command in psql. PGresult *results was not freed most of the time.There is still a leak being detected (2 bytes) in readline functions, butI think this is old readline library. I will install new one and test it.
1 parentd955727 commit9a5529f

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

‎src/bin/psql/psql.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.66 1997/05/24 14:38:05 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.67 1997/06/01 15:38:42 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -612,6 +612,7 @@ SendQuery(bool * success_p, PsqlSettings * settings, const char *query,
612612
notify->relname,notify->be_pid);
613613
free(notify);
614614
}
615+
PQclear(results);
615616
}
616617
}
617618

‎src/interfaces/libpq/fe-connect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.35 1997/05/20 03:38:49 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.36 1997/06/01 15:38:52 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -588,6 +588,7 @@ freePGconn(PGconn *conn)
588588
if (conn->dbName)free(conn->dbName);
589589
if (conn->pguser)free(conn->pguser);
590590
if (conn->notifyList)DLFreeList(conn->notifyList);
591+
if (conn->port)free(conn->port);
591592
free(conn);
592593
}
593594

‎src/interfaces/libpq/fe-exec.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.31 1997/06/0104:59:25 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.32 1997/06/0115:39:08 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -58,6 +58,9 @@ static void addTuple(PGresult *res, PGresAttValue *tup);
5858
staticPGresAttValue*getTuple(PGconn*conn,PGresult*res,intbinary);
5959
staticPGresult*makeEmptyPGresult(PGconn*conn,ExecStatusTypestatus);
6060
staticvoidfill(intlength,intmax,charfiller,FILE*fp);
61+
staticchar*do_header(FILE*fout,PQprintOpt*po,constintnFields,
62+
intfieldMax[],char*fieldNames[],unsignedcharfieldNotNum[],
63+
constintfs_len,PGresult*res);
6164

6265
/*
6366
* PQclear -
@@ -78,16 +81,16 @@ PQclear(PGresult* res)
7881
if (res->tuples[i][j].value)
7982
free(res->tuples[i][j].value);
8083
}
81-
free(res->tuples[i]);
84+
if (res->tuples[i])free(res->tuples[i]);
8285
}
83-
free(res->tuples);
86+
if (res->tuples)free(res->tuples);
8487

8588
/* free all the attributes */
8689
for (i=0;i<res->numAttributes;i++) {
8790
if (res->attDescs[i].name)
8891
free(res->attDescs[i].name);
8992
}
90-
free(res->attDescs);
93+
if (res->attDescs)free(res->attDescs);
9194

9295
/* free the structure itself */
9396
free(res);
@@ -590,8 +593,6 @@ PQexec(PGconn* conn, const char* query)
590593
return(result);
591594
}
592595

593-
594-
595596
/*
596597
* PQnotifies
597598
* returns a PGnotify* structure of the latest async notification
@@ -663,7 +664,6 @@ PQgetline(PGconn *conn, char *s, int maxlen)
663664
return(1);/* returning a full buffer */
664665
}
665666

666-
667667
/*
668668
* PQputline -- sends a string to the backend.
669669
*
@@ -734,7 +734,6 @@ fill (int length, int max, char filler, FILE *fp)
734734
}
735735
}
736736

737-
738737
/*
739738
* PQdisplayTuples()
740739
* kept for backward compatibility
@@ -973,28 +972,31 @@ do_field(PQprintOpt *po, PGresult *res,
973972
}
974973

975974

976-
staticvoid
975+
staticchar*
977976
do_header(FILE*fout,PQprintOpt*po,constintnFields,intfieldMax[],
978977
char*fieldNames[],unsignedcharfieldNotNum[],
979-
constintfs_len,char*border,PGresult*res) {
978+
constintfs_len,PGresult*res) {
980979

981980
intj;/* for loop index */
981+
char*border=NULL;
982982

983983
if (po->html3)
984984
fputs("<tr>",fout);
985985
else {
986986
intj;/* for loop index */
987987
inttot=0;
988988
intn=0;
989-
char*p;
989+
char*p=NULL;
990990
for (;n<nFields;n++)
991991
tot+=fieldMax[n]+fs_len+(po->standard?2:0);
992992
if (po->standard)
993993
tot+=fs_len*2+2;
994-
if (!(p=border=malloc(tot+1))) {
994+
border=malloc(tot+1);
995+
if (!border) {
995996
perror("malloc");
996997
exit(1);
997998
}
999+
p=border;
9981000
if (po->standard) {
9991001
char*fs=po->fieldSep;
10001002
while (*fs++)
@@ -1038,6 +1040,7 @@ do_header(FILE *fout, PQprintOpt *po, const int nFields, int fieldMax[],
10381040
fputs("</tr>\n",fout);
10391041
else
10401042
fprintf(fout,"\n%s\n",border);
1043+
returnborder;
10411044
}
10421045

10431046

@@ -1262,12 +1265,14 @@ PQprint(FILE *fout,
12621265
fprintf(fout,"<table %s>",po->tableOpt?po->tableOpt:"");
12631266
}
12641267
if (po->header)
1265-
do_header(fout,po,nFields,fieldMax,fieldNames,fieldNotNum,
1266-
fs_len,border,res);
1268+
border=do_header(fout,po,nFields,fieldMax,fieldNames,
1269+
fieldNotNum,fs_len,res);
12671270
for (i=0;i<nTups;i++)
12681271
output_row(fout,po,nFields,fields,
12691272
fieldNotNum,fieldMax,border,i);
12701273
free(fields);
1274+
if (border)
1275+
free(border);
12711276
}
12721277
if (po->header&& !po->html3)
12731278
fprintf (fout,"(%d row%s)\n\n",PQntuples(res),
@@ -1279,8 +1284,6 @@ PQprint(FILE *fout,
12791284
pclose(fout);
12801285
pqsignal(SIGPIPE,SIG_DFL);
12811286
}
1282-
if (border)
1283-
free(border);
12841287
if (po->html3&& !po->expanded)
12851288
fputs("</table>\n",fout);
12861289
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp