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/variables.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/variables.c')
-rw-r--r-- | src/bin/psql/variables.c | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c index 21dc8aecb68..31c5510ad83 100644 --- a/src/bin/psql/variables.c +++ b/src/bin/psql/variables.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.15 2003/12/01 22:14:40 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/variables.c,v 1.16 2004/01/24 19:38:49 neilc Exp $ */ #include "postgres_fe.h" #include "common.h" @@ -14,19 +14,9 @@ CreateVariableSpace(void) { struct _variable *ptr; - ptr = calloc(1, sizeof *ptr); - if (!ptr) - return NULL; - - ptr->name = strdup("@"); - ptr->value = strdup(""); - if (!ptr->name || !ptr->value) - { - free(ptr->name); - free(ptr->value); - free(ptr); - return NULL; - } + ptr = xcalloc(1, sizeof *ptr); + ptr->name = xstrdup("@"); + ptr->value = xstrdup(""); return ptr; } @@ -162,19 +152,15 @@ SetVariable(VariableSpace space, const char *name, const char *value) if (strcmp(current->name, name) == 0) { free(current->value); - current->value = strdup(value); - return current->value ? true : false; + current->value = xstrdup(value); + return true; } } - previous->next = calloc(1, sizeof *(previous->next)); - if (!previous->next) - return false; - previous->next->name = strdup(name); - if (!previous->next->name) - return false; - previous->next->value = strdup(value); - return previous->next->value ? true : false; + previous->next = xcalloc(1, sizeof *(previous->next)); + previous->next->name = xstrdup(name); + previous->next->value = xstrdup(value); + return true; } bool |