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

Commitaa158a7

Browse files
committed
Fix memory leak from Tom Lane.
1 parent3ac9688 commitaa158a7

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

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

Lines changed: 4 additions & 4 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-connect.c,v 1.82 1998/09/18 16:46:05 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.83 1998/09/20 04:51:10 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1316,9 +1316,8 @@ conninfo_parse(const char *conninfo, char *errorMessage)
13161316
*/
13171317
if (!strcmp(option->keyword,"user"))
13181318
{
1319-
tmp=fe_getauthname(errortmp);
1320-
if (tmp)
1321-
option->val=strdup(tmp);
1319+
option->val=fe_getauthname(errortmp);
1320+
continue;
13221321
}
13231322

13241323
/* ----------
@@ -1330,6 +1329,7 @@ conninfo_parse(const char *conninfo, char *errorMessage)
13301329
tmp=conninfo_getval("user");
13311330
if (tmp)
13321331
option->val=strdup(tmp);
1332+
continue;
13331333
}
13341334
}
13351335

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
*
2626
* IDENTIFICATION
27-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.21 1998/09/03 02:10:50 momjian Exp $
27+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.22 1998/09/20 04:51:12 momjian Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -366,6 +366,11 @@ pqReadData(PGconn *conn)
366366
#if defined(EWOULDBLOCK)&& (!defined(EAGAIN)|| (EWOULDBLOCK!=EAGAIN))
367367
if (errno==EWOULDBLOCK)
368368
return0;
369+
#endif
370+
/* We might get ECONNRESET here if using TCP and backend died */
371+
#ifdefECONNRESET
372+
if (errno==ECONNRESET)
373+
gotodefinitelyFailed;
369374
#endif
370375
sprintf(conn->errorMessage,
371376
"pqReadData() -- read() failed: errno=%d\n%s\n",
@@ -409,6 +414,11 @@ pqReadData(PGconn *conn)
409414
#if defined(EWOULDBLOCK)&& (!defined(EAGAIN)|| (EWOULDBLOCK!=EAGAIN))
410415
if (errno==EWOULDBLOCK)
411416
return0;
417+
#endif
418+
/* We might get ECONNRESET here if using TCP and backend died */
419+
#ifdefECONNRESET
420+
if (errno==ECONNRESET)
421+
gotodefinitelyFailed;
412422
#endif
413423
sprintf(conn->errorMessage,
414424
"pqReadData() -- read() failed: errno=%d\n%s\n",
@@ -425,6 +435,7 @@ pqReadData(PGconn *conn)
425435
* OK, we are getting a zero read even though select() says ready.
426436
* This means the connection has been closed. Cope.
427437
*/
438+
definitelyFailed:
428439
sprintf(conn->errorMessage,
429440
"pqReadData() -- backend closed the channel unexpectedly.\n"
430441
"\tThis probably means the backend terminated abnormally"
@@ -460,7 +471,6 @@ pqFlush(PGconn *conn)
460471
/* Prevent being SIGPIPEd if backend has closed the connection. */
461472
#ifndefWIN32
462473
pqsigfuncoldsighandler=pqsignal(SIGPIPE,SIG_IGN);
463-
464474
#endif
465475

466476
intsent=send(conn->sock,ptr,len,0);
@@ -471,7 +481,11 @@ pqFlush(PGconn *conn)
471481

472482
if (sent<0)
473483
{
474-
/* Anything except EAGAIN or EWOULDBLOCK is trouble */
484+
/*
485+
* Anything except EAGAIN or EWOULDBLOCK is trouble.
486+
* If it's EPIPE or ECONNRESET, assume we've lost the
487+
* backend connection permanently.
488+
*/
475489
switch (errno)
476490
{
477491
#ifdefEAGAIN
@@ -482,10 +496,27 @@ pqFlush(PGconn *conn)
482496
caseEWOULDBLOCK:
483497
break;
484498
#endif
499+
caseEPIPE:
500+
#ifdefECONNRESET
501+
caseECONNRESET:
502+
#endif
503+
sprintf(conn->errorMessage,
504+
"pqFlush() -- backend closed the channel unexpectedly.\n"
505+
"\tThis probably means the backend terminated abnormally"
506+
" before or while processing the request.\n");
507+
conn->status=CONNECTION_BAD;/* No more connection */
508+
#ifdefWIN32
509+
closesocket(conn->sock);
510+
#else
511+
close(conn->sock);
512+
#endif
513+
conn->sock=-1;
514+
returnEOF;
485515
default:
486516
sprintf(conn->errorMessage,
487-
"pqFlush() -- couldn't send data: errno=%d\n%s\n",
517+
"pqFlush() -- couldn't send data: errno=%d\n%s\n",
488518
errno,strerror(errno));
519+
/* We don't assume it's a fatal error... */
489520
returnEOF;
490521
}
491522
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp