Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36ba263

Browse files
committed
Clean up failure to use ClosePager() where appropriate in help.c.
Also prevent possible repeat opening of pager in helpSQL().
1 parent debcec7 commit 36ba263

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

src/bin/psql/help.c

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
*
44
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.161 2010/08/12 00:40:59 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.162 2010/08/13 20:56:18 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99

10-
#include <signal.h>
11-
1210
#ifndef WIN32
1311
#ifdef HAVE_PWD_H
1412
#include <pwd.h> /* for getpwuid() */
@@ -27,8 +25,6 @@
2725
#include <termios.h>
2826
#endif
2927

30-
#include "pqsignal.h"
31-
3228
#include "common.h"
3329
#include "help.h"
3430
#include "input.h"
@@ -271,13 +267,7 @@ slashUsage(unsigned short int pager)
271267
" \\lo_list\n"
272268
" \\lo_unlink LOBOID large object operations\n"));
273269

274-
if (output != stdout)
275-
{
276-
pclose(output);
277-
#ifndef WIN32
278-
pqsignal(SIGPIPE, SIG_DFL);
279-
#endif
280-
}
270+
ClosePager(output);
281271
}
282272

283273

@@ -334,22 +324,15 @@ helpSQL(const char *topic, unsigned short int pager)
334324
fputc('\n', output);
335325
}
336326

337-
/* Only close if we used the pager */
338-
if (output != stdout)
339-
{
340-
pclose(output);
341-
#ifndef WIN32
342-
pqsignal(SIGPIPE, SIG_DFL);
343-
#endif
344-
}
327+
ClosePager(output);
345328
}
346329
else
347330
{
348331
int i,
349332
j,
350333
x = 0;
351334
bool help_found = false;
352-
FILE *output;
335+
FILE *output = NULL;
353336
size_t len,
354337
wordlen;
355338
int nl_count = 0;
@@ -376,7 +359,8 @@ helpSQL(const char *topic, unsigned short int pager)
376359
}
377360
if (wordlen >= len) /* Don't try again if the same word */
378361
{
379-
output = PageOutput(nl_count, pager);
362+
if (!output)
363+
output = PageOutput(nl_count, pager);
380364
break;
381365
}
382366
len = wordlen;
@@ -396,7 +380,8 @@ helpSQL(const char *topic, unsigned short int pager)
396380
}
397381
}
398382

399-
output = PageOutput(nl_count, pager);
383+
if (!output)
384+
output = PageOutput(nl_count, pager);
400385

401386
for (i = 0; QL_HELP[i].cmd; i++)
402387
{
@@ -426,14 +411,7 @@ helpSQL(const char *topic, unsigned short int pager)
426411
if (!help_found)
427412
fprintf(output, _("No help available for \"%s\".\nTry \\h with no arguments to see available help.\n"), topic);
428413

429-
/* Only close if we used the pager */
430-
if (output != stdout)
431-
{
432-
pclose(output);
433-
#ifndef WIN32
434-
pqsignal(SIGPIPE, SIG_DFL);
435-
#endif
436-
}
414+
ClosePager(output);
437415
}
438416
}
439417

0 commit comments

Comments
 (0)