1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +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:
Neil Conway
2004-01-24 19:38:49 +00:00
parent cb3dc829f6
commit 610d33c194
13 changed files with 124 additions and 237 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.37 2004/01/20 23:48:56 tgl Exp $
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.38 2004/01/24 19:38:49 neilc Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
@ -83,12 +83,7 @@ xstrcat(char **var, const char *more)
{
char *newvar;
newvar = (char *) malloc(strlen(*var) + strlen(more) + 1);
if (!newvar)
{
psql_error("out of memory\n");
exit(EXIT_FAILURE);
}
newvar = xmalloc(strlen(*var) + strlen(more) + 1);
strcpy(newvar, *var);
strcat(newvar, more);
free(*var);
@ -112,11 +107,7 @@ parse_slash_copy(const char *args)
return NULL;
}
if (!(result = calloc(1, sizeof(struct copy_options))))
{
psql_error("out of memory\n");
exit(EXIT_FAILURE);
}
result = xcalloc(1, sizeof(struct copy_options));
token = strtokx(line, whitespace, ".,()", "\"",
0, false, pset.encoding);