diff options
author | Neil Conway <neilc@samurai.com> | 2004-01-24 19:38:49 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2004-01-24 19:38:49 +0000 |
commit | 610d33c1949005e9658863441f31083f9f3ceb9b (patch) | |
tree | 861eb9dfec8dc43b4f5716f48aa52d4468128a90 /src/bin/psql/input.c | |
parent | cb3dc829f639801219aab4ec35e53ef924ce75c5 (diff) | |
download | postgresql-610d33c1949005e9658863441f31083f9f3ceb9b.tar.gz postgresql-610d33c1949005e9658863441f31083f9f3ceb9b.zip |
This patch makes some of the memory manipulation performed by psql a
little more sane. Some parts of the code was using a static function
xmalloc() that did safe memory allocation (where "safe" means "bail
out on OOM"), but most of it was just invoking calloc() or malloc()
directly. Now almost everything invokes xmalloc() or xcalloc().
Diffstat (limited to 'src/bin/psql/input.c')
-rw-r--r-- | src/bin/psql/input.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 90c2c92993d..6a2afa35bd3 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.32 2003/11/29 19:52:06 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.33 2004/01/24 19:38:49 neilc Exp $ */ #include "postgres_fe.h" #include "input.h" @@ -83,7 +83,7 @@ gets_basic(const char prompt[]) * gets_interactive() * * Gets a line of interactive input, using readline of desired. - * The result is malloced. + * The result is malloc'ed. */ char * gets_interactive(const char *prompt) @@ -113,7 +113,7 @@ gets_interactive(const char *prompt) else { free(prev_hist); - prev_hist = strdup(s); + prev_hist = xstrdup(s); add_history(s); } } @@ -183,15 +183,13 @@ initializeInput(int flags) home = getenv("HOME"); if (home) { - char *psql_history = (char *) malloc(strlen(home) + 1 + - strlen(PSQLHISTORY) + 1); - - if (psql_history) - { - sprintf(psql_history, "%s/%s", home, PSQLHISTORY); - read_history(psql_history); - free(psql_history); - } + char *psql_history; + + psql_history = xmalloc(strlen(home) + 1 + + strlen(PSQLHISTORY) + 1); + sprintf(psql_history, "%s/%s", home, PSQLHISTORY); + read_history(psql_history); + free(psql_history); } } #endif @@ -234,26 +232,24 @@ finishInput(int exitstatus, void *arg) if (useHistory) { char *home; - char *psql_history; home = getenv("HOME"); if (home) { - psql_history = (char *) malloc(strlen(home) + 1 + - strlen(PSQLHISTORY) + 1); - if (psql_history) - { - int hist_size; + char *psql_history; + int hist_size; + + psql_history = xmalloc(strlen(home) + 1 + + strlen(PSQLHISTORY) + 1); - hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true); + hist_size = GetVariableNum(pset.vars, "HISTSIZE", -1, -1, true); - if (hist_size >= 0) - stifle_history(hist_size); + if (hist_size >= 0) + stifle_history(hist_size); - sprintf(psql_history, "%s/%s", home, PSQLHISTORY); - write_history(psql_history); - free(psql_history); - } + sprintf(psql_history, "%s/%s", home, PSQLHISTORY); + write_history(psql_history); + free(psql_history); } } #endif |