mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +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/common.c,v 1.80 2004/01/20 23:48:56 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.81 2004/01/24 19:38:49 neilc Exp $
|
||||
*/
|
||||
#include "postgres_fe.h"
|
||||
#include "common.h"
|
||||
@@ -89,6 +89,43 @@ xstrdup(const char *string)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void *
|
||||
xmalloc(size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
tmp = malloc(size);
|
||||
if (!tmp)
|
||||
{
|
||||
psql_error("out of memory\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void *
|
||||
xmalloc_zero(size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
tmp = xmalloc(size);
|
||||
memset(tmp, 0, size);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void *
|
||||
xcalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
tmp = calloc(nmemb, size);
|
||||
if (!tmp)
|
||||
{
|
||||
psql_error("out of memory");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -854,12 +891,7 @@ expand_tilde(char **filename)
|
||||
{
|
||||
char *newfn;
|
||||
|
||||
newfn = malloc(strlen(home) + strlen(p) + 1);
|
||||
if (!newfn)
|
||||
{
|
||||
psql_error("out of memory\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
newfn = xmalloc(strlen(home) + strlen(p) + 1);
|
||||
strcpy(newfn, home);
|
||||
strcat(newfn, p);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user