Commit 6399c74f authored by Bruce Momjian's avatar Bruce Momjian

Fix \g filename. Free allocated memory and don't use memory that has

been freed.
parent 9d45f22e
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.29 1996/11/14 16:08:03 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.30 1996/11/20 22:34:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -475,6 +475,7 @@ SendQuery(bool * success_p, PsqlSettings * settings, const char *query, ...@@ -475,6 +475,7 @@ SendQuery(bool * success_p, PsqlSettings * settings, const char *query,
pclose(fp); pclose(fp);
else else
fclose(fp); fclose(fp);
free(settings->gfname);
settings->gfname = NULL; settings->gfname = NULL;
break; break;
} else { } else {
...@@ -1011,7 +1012,11 @@ HandleSlashCmds(PsqlSettings * settings, ...@@ -1011,7 +1012,11 @@ HandleSlashCmds(PsqlSettings * settings,
if (settings->opt.caption) if (settings->opt.caption)
free(settings->opt.caption); free(settings->opt.caption);
if (!optarg) if (!optarg)
{
if (settings->opt.caption)
free(settings->opt.caption);
settings->opt.caption = NULL; settings->opt.caption = NULL;
}
else if (!(settings->opt.caption = strdup(optarg))) { else if (!(settings->opt.caption = strdup(optarg))) {
perror("malloc"); perror("malloc");
exit(1); exit(1);
...@@ -1083,7 +1088,7 @@ HandleSlashCmds(PsqlSettings * settings, ...@@ -1083,7 +1088,7 @@ HandleSlashCmds(PsqlSettings * settings,
if (optarg) if (optarg)
fs = optarg; fs = optarg;
if (settings->opt.fieldSep); if (settings->opt.fieldSep);
free(settings->opt.fieldSep); free(settings->opt.fieldSep);
if (!(settings->opt.fieldSep = strdup(fs))) { if (!(settings->opt.fieldSep = strdup(fs))) {
perror("malloc"); perror("malloc");
exit(1); exit(1);
...@@ -1093,7 +1098,7 @@ HandleSlashCmds(PsqlSettings * settings, ...@@ -1093,7 +1098,7 @@ HandleSlashCmds(PsqlSettings * settings,
break; break;
} }
case 'g': /* \g means send query */ case 'g': /* \g means send query */
settings->gfname = optarg; settings->gfname = strdup(optarg);
status = 0; status = 0;
break; break;
case 'h': /* help */ case 'h': /* help */
...@@ -1151,12 +1156,14 @@ HandleSlashCmds(PsqlSettings * settings, ...@@ -1151,12 +1156,14 @@ HandleSlashCmds(PsqlSettings * settings,
if (toggle(settings, &settings->opt.standard, "standard SQL separaters and padding")) { if (toggle(settings, &settings->opt.standard, "standard SQL separaters and padding")) {
settings->opt.html3 = settings->opt.expanded = 0; settings->opt.html3 = settings->opt.expanded = 0;
settings->opt.align = settings->opt.header = 1; settings->opt.align = settings->opt.header = 1;
free(settings->opt.fieldSep); if (settings->opt.fieldSep)
free(settings->opt.fieldSep);
settings->opt.fieldSep = strdup("|"); settings->opt.fieldSep = strdup("|");
if (!settings->quiet) if (!settings->quiet)
fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep); fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep);
} else { } else {
free(settings->opt.fieldSep); if (settings->opt.fieldSep)
free(settings->opt.fieldSep);
settings->opt.fieldSep = strdup(DEFAULT_FIELD_SEP); settings->opt.fieldSep = strdup(DEFAULT_FIELD_SEP);
if (!settings->quiet) if (!settings->quiet)
fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep); fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment