From 157d40640cdd885b72f27db358ba66d12feaec7d Mon Sep 17 00:00:00 2001 From: Michael Meskes Date: Thu, 5 Feb 2015 15:12:34 +0100 Subject: 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 --- src/interfaces/ecpg/ecpglib/memory.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/interfaces/ecpg/ecpglib/memory.c') 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 -- cgit v1.2.3