aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/ecpglib/memory.c
diff options
context:
space:
mode:
authorMichael Meskes <meskes@postgresql.org>2015-02-05 15:12:34 +0100
committerMichael Meskes <meskes@postgresql.org>2015-08-12 13:56:38 +0200
commit157d40640cdd885b72f27db358ba66d12feaec7d (patch)
treed1c4970ce8388dbb66229136501cf4bf8f9094f3 /src/interfaces/ecpg/ecpglib/memory.c
parenta35a527f2d6b28f78e9eab42801ec0170ffcb898 (diff)
downloadpostgresql-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.c22
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