Skip to content

Commit 1f0aff0

Browse files
committed
Remove calls to getprotobyname(), which we now know leaks memory on
some platforms --- and I also see that it is documented as not thread- safe on HPUX and possibly other platforms. No good reason not to just use IPPROTO_TCP constant from <netinet/in.h> instead.
1 parent 9dab9ab commit 1f0aff0

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
3030
* Portions Copyright (c) 1994, Regents of the University of California
3131
*
32-
* $Id: pqcomm.c,v 1.90 2000/05/20 13:10:54 ishii Exp $
32+
* $Id: pqcomm.c,v 1.91 2000/05/21 21:19:53 tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -360,19 +360,12 @@ StreamConnection(int server_fd, Port *port)
360360
return STATUS_ERROR;
361361
}
362362

363-
/* select TCP_NODELAY option if it's a TCP connection */
363+
/* select NODELAY and KEEPALIVE options if it's a TCP connection */
364364
if (port->laddr.sa.sa_family == AF_INET)
365365
{
366-
struct protoent *pe;
367366
int on = 1;
368367

369-
pe = getprotobyname("TCP");
370-
if (pe == NULL)
371-
{
372-
perror("postmaster: StreamConnection: getprotobyname");
373-
return STATUS_ERROR;
374-
}
375-
if (setsockopt(port->sock, pe->p_proto, TCP_NODELAY,
368+
if (setsockopt(port->sock, IPPROTO_TCP, TCP_NODELAY,
376369
&on, sizeof(on)) < 0)
377370
{
378371
perror("postmaster: StreamConnection: setsockopt(TCP_NODELAY)");

src/interfaces/libpq/fe-connect.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.126 2000/04/12 17:17:14 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.127 2000/05/21 21:19:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,6 +29,7 @@
2929
#include <sys/socket.h>
3030
#include <unistd.h>
3131
#include <netdb.h>
32+
#include <netinet/in.h>
3233
#include <netinet/tcp.h>
3334
#include <arpa/inet.h>
3435
#endif
@@ -625,19 +626,9 @@ connectMakeNonblocking(PGconn *conn)
625626
static int
626627
connectNoDelay(PGconn *conn)
627628
{
628-
struct protoent *pe;
629629
int on = 1;
630630

631-
pe = getprotobyname("TCP");
632-
if (pe == NULL)
633-
{
634-
printfPQExpBuffer(&conn->errorMessage,
635-
"connectNoDelay() -- "
636-
"getprotobyname failed: errno=%d\n%s\n",
637-
errno, strerror(errno));
638-
return 0;
639-
}
640-
if (setsockopt(conn->sock, pe->p_proto, TCP_NODELAY,
631+
if (setsockopt(conn->sock, IPPROTO_TCP, TCP_NODELAY,
641632
#ifdef WIN32
642633
(char *)
643634
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy