diff options
author | Michael Meskes <meskes@postgresql.org> | 2015-02-05 15:12:34 +0100 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2015-08-12 13:56:38 +0200 |
commit | 157d40640cdd885b72f27db358ba66d12feaec7d (patch) | |
tree | d1c4970ce8388dbb66229136501cf4bf8f9094f3 /src/interfaces/ecpg/ecpglib/memory.c | |
parent | a35a527f2d6b28f78e9eab42801ec0170ffcb898 (diff) | |
download | postgresql-157d40640cdd885b72f27db358ba66d12feaec7d.tar.gz postgresql-157d40640cdd885b72f27db358ba66d12feaec7d.zip |
This routine was calling ecpg_alloc to allocate to memory but did not
actually check the returned pointer allocated, potentially NULL which
could be the result of a malloc call.
Issue noted by Coverity, fixed by Michael Paquier <michael@otacoo.com>
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/memory.c')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/memory.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/ecpglib/memory.c b/src/interfaces/ecpg/ecpglib/memory.c index a09cd26a542..dffc3a76187 100644 --- a/src/interfaces/ecpg/ecpglib/memory.c +++ b/src/interfaces/ecpg/ecpglib/memory.c @@ -104,14 +104,34 @@ static struct auto_mem *auto_allocs = NULL; #define set_auto_allocs(am) do { auto_allocs = (am); } while(0) #endif -void +char * +ecpg_auto_alloc(long size, int lineno) +{ + void *ptr = (void *) ecpg_alloc(size, lineno); + + if (!ptr) + return NULL; + + if (!ecpg_add_mem(ptr, lineno)) + { + ecpg_free(ptr); + return NULL; + } + return ptr; +} + +bool ecpg_add_mem(void *ptr, int lineno) { struct auto_mem *am = (struct auto_mem *) ecpg_alloc(sizeof(struct auto_mem), lineno); + if (!am) + return false; + am->pointer = ptr; am->next = get_auto_allocs(); set_auto_allocs(am); + return true; } void |