diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-02 15:35:10 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-02 15:35:48 -0400 |
commit | a563d941803535dbd27d4191fe7729497b7fdf31 (patch) | |
tree | 79048d522a1b35451381970fcec821e18f3cf0ab /src/bin/scripts/common.c | |
parent | 779f80b75d448d61cf3388645505c9fd81000bb2 (diff) | |
download | postgresql-a563d941803535dbd27d4191fe7729497b7fdf31.tar.gz postgresql-a563d941803535dbd27d4191fe7729497b7fdf31.zip |
Standardize naming of malloc/realloc/strdup wrapper functions.
We had a number of variants on the theme of "malloc or die", with the
majority named like "pg_malloc", but by no means all. Standardize on the
names pg_malloc, pg_malloc0, pg_realloc, pg_strdup. Get rid of pg_calloc
entirely in favor of using pg_malloc0.
This is an essentially cosmetic change, so no back-patch. (I did find
a couple of places where psql and pg_dump were using plain malloc or
strdup instead of the pg_ versions, but they don't look significant
enough to bother back-patching.)
Diffstat (limited to 'src/bin/scripts/common.c')
-rw-r--r-- | src/bin/scripts/common.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c index 0ae708b21ea..4a7d02f7771 100644 --- a/src/bin/scripts/common.c +++ b/src/bin/scripts/common.c @@ -109,14 +109,8 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport, do { #define PARAMS_ARRAY_SIZE 7 - const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords)); - const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values)); - - if (!keywords || !values) - { - fprintf(stderr, _("%s: out of memory\n"), progname); - exit(1); - } + const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords)); + const char **values = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*values)); keywords[0] = "host"; values[0] = pghost; @@ -305,6 +299,30 @@ pg_strdup(const char *string) return tmp; } +void * +pg_malloc(size_t size) +{ + void *tmp; + + tmp = malloc(size); + if (!tmp) + { + fprintf(stderr, _("out of memory\n")); + exit(EXIT_FAILURE); + } + return tmp; +} + +void * +pg_malloc0(size_t size) +{ + void *tmp; + + tmp = pg_malloc(size); + MemSet(tmp, 0, size); + return tmp; +} + /* * Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither. */ |