mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
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().
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user