diff --git a/http.c b/http.c index 0b8c811..56c7c46 100644 --- a/http.c +++ b/http.c @@ -314,25 +314,35 @@ http_strtolower(const char *input) #if PG_VERSION_NUM < 160000 +static void * +guc_malloc(int elevel, size_t size) +{ + void *data; + + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; + data = malloc(size); + if (data == NULL) + ereport(elevel, + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); + return data; +} + static char * guc_strdup(int elevel, const char *src) { - char *data; - MemoryContext oldcontext = MemoryContextSwitchTo(CacheMemoryContext); - data = pstrdup(src); - MemoryContextSwitchTo(oldcontext); - - if (data == NULL) - ereport(elevel, - (errcode(ERRCODE_OUT_OF_MEMORY), - errmsg("out of memory"))); - return data; + size_t len = strlen(src) + 1; + char *dup = guc_malloc(elevel, len); + memcpy(dup, src, len); + return dup; } static void guc_free(void *ptr) { - pfree(ptr); + free(ptr); } #endif