diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-08-30 18:22:43 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-08-30 18:22:43 -0400 |
commit | 052cc223d5ce1b727f62afff75797c88d82f880b (patch) | |
tree | bc60ab35a639f80fd33d8f3391558084d680dbae /src/backend/utils/misc/ps_status.c | |
parent | 9daec77e165de461fca9d5bc3ece86a91aba5804 (diff) |
Fix a bunch of places that called malloc and friends with no NULL check.
Where possible, use palloc or pg_malloc instead; otherwise, insert
explicit NULL checks.
Generally speaking, these are places where an actual OOM is quite
unlikely, either because they're in client programs that don't
allocate all that much, or they're very early in process startup
so that we'd likely have had a fork() failure instead. Hence,
no back-patch, even though this is nominally a bug fix.
Michael Paquier, with some adjustments by me
Discussion: <CAB7nPqRu07Ot6iht9i9KRfYLpDaF2ZuUv5y_+72uP23ZAGysRg@mail.gmail.com>
Diffstat (limited to 'src/backend/utils/misc/ps_status.c')
-rw-r--r-- | src/backend/utils/misc/ps_status.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index 892a810baba..c50be8aab65 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -113,6 +113,9 @@ static char **save_argv; * overwritten during init_ps_display. Also, the physical location of the * environment strings may be moved, so this should be called before any code * that might try to hang onto a getenv() result.) + * + * Note that in case of failure this cannot call elog() as that is not + * initialized yet. We rely on write_stderr() instead. */ char ** save_ps_display_args(int argc, char **argv) @@ -163,8 +166,20 @@ save_ps_display_args(int argc, char **argv) * move the environment out of the way */ new_environ = (char **) malloc((i + 1) * sizeof(char *)); + if (!new_environ) + { + write_stderr("out of memory\n"); + exit(1); + } for (i = 0; environ[i] != NULL; i++) + { new_environ[i] = strdup(environ[i]); + if (!new_environ[i]) + { + write_stderr("out of memory\n"); + exit(1); + } + } new_environ[i] = NULL; environ = new_environ; } @@ -189,8 +204,20 @@ save_ps_display_args(int argc, char **argv) int i; new_argv = (char **) malloc((argc + 1) * sizeof(char *)); + if (!new_argv) + { + write_stderr("out of memory\n"); + exit(1); + } for (i = 0; i < argc; i++) + { new_argv[i] = strdup(argv[i]); + if (!new_argv[i]) + { + write_stderr("out of memory\n"); + exit(1); + } + } new_argv[argc] = NULL; #if defined(__darwin__) |