20150612_pltcl_oom.patch
text/x-diff
Filename: 20150612_pltcl_oom.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/pl/tcl/pltcl.c | 28 | 0 |
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index d6b72f7..d0a5de4 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -2134,11 +2134,39 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
* Allocate the new querydesc structure
************************************************************/
qdesc = (pltcl_query_desc *) malloc(sizeof(pltcl_query_desc));
+ if (qdesc == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
snprintf(qdesc->qname, sizeof(qdesc->qname), "%p", qdesc);
qdesc->nargs = nargs;
qdesc->argtypes = (Oid *) malloc(nargs * sizeof(Oid));
+ if (qdesc->argtypes == NULL)
+ {
+ free(qdesc);
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
+ }
qdesc->arginfuncs = (FmgrInfo *) malloc(nargs * sizeof(FmgrInfo));
+ if (qdesc->arginfuncs == NULL)
+ {
+ free(qdesc->argtypes);
+ free(qdesc);
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
+ }
qdesc->argtypioparams = (Oid *) malloc(nargs * sizeof(Oid));
+ if (qdesc->argtypioparams == NULL)
+ {
+ free(qdesc->arginfuncs);
+ free(qdesc->argtypes);
+ free(qdesc);
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
+ }
/************************************************************
* Execute the prepare inside a sub-transaction, so we can cope with