--- ngx_http_charset_filter_module.c.orig	2019-12-12 12:45:49.023069600 -0800
+++ ngx_http_charset_filter_module.c	2019-12-12 13:47:06.566471000 -0800
@@ -1112,6 +1112,7 @@
 
     cl->buf = ngx_calloc_buf(pool);
     if (cl->buf == NULL) {
+	ngx_free_chain(cl); /*	release memory allocated to cl */
         return NULL;
     }
 
@@ -1229,11 +1230,14 @@
 
         table->dst2src = ngx_pcalloc(cf->pool, 256 * sizeof(void *));
         if (table->dst2src == NULL) {
+	    ngx_pfree(table->src2dst);	/* release memory allocated to table->src2dst */
             return NGX_CONF_ERROR;
         }
 
         dst2src = ngx_pcalloc(cf->pool, 256);
         if (dst2src == NULL) {
+	    ngx_pfree(table->dst2src);	/* release memory allocated to table->dst2src */
+	    ngx_pfree(table->src2dst);	/* release memory allocated to table->src2dst */
             return NGX_CONF_ERROR;
         }
 
@@ -1665,6 +1669,7 @@
         if (dst == NULL) {
             dst = ngx_pcalloc(cf->pool, sizeof(u_char *) * mcf->charsets.nelts);
             if (dst == NULL) {
+		ngx_pfree(src);	/*  release memory allocated to src */
                 return NGX_ERROR;
             }
 
