Commit a88dbf91 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fix a memory leak in BAN processing: We didn't free the compiled regexp.

Also solve a abstract corner-case when malloc(3) fails.  We'll probably
still come crashing down, but not for this reason any more.
parent 13e2f2c6
...@@ -811,6 +811,7 @@ struct ban *BAN_New(void); ...@@ -811,6 +811,7 @@ struct ban *BAN_New(void);
int BAN_AddTest(struct ban *, const char *, const char *, const char *); int BAN_AddTest(struct ban *, const char *, const char *, const char *);
void BAN_Free(struct ban *b); void BAN_Free(struct ban *b);
char *BAN_Insert(struct ban *b); char *BAN_Insert(struct ban *b);
void BAN_Free_Errormsg(char *);
void BAN_Init(void); void BAN_Init(void);
void BAN_Shutdown(void); void BAN_Shutdown(void);
void BAN_NewObjCore(struct objcore *oc); void BAN_NewObjCore(struct objcore *oc);
......
...@@ -394,6 +394,7 @@ ban_parse_regexp(struct ban *b, const char *a3) ...@@ -394,6 +394,7 @@ ban_parse_regexp(struct ban *b, const char *a3)
rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &sz); rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &sz);
AZ(rc); AZ(rc);
ban_add_lump(b, re, sz); ban_add_lump(b, re, sz);
pcre_free(re);
return (0); return (0);
} }
...@@ -464,19 +465,27 @@ BAN_AddTest(struct ban *b, const char *a1, const char *a2, const char *a3) ...@@ -464,19 +465,27 @@ BAN_AddTest(struct ban *b, const char *a1, const char *a2, const char *a3)
* deleted. * deleted.
*/ */
static char ban_error_nomem[] = "Could not get memory";
static char * static char *
ban_ins_error(const char *p) ban_ins_error(const char *p)
{ {
char *r = NULL; char *r = NULL;
static char nomem[] = "Could not get memory";
if (p != NULL) if (p != NULL)
r = strdup(p); r = strdup(p);
if (r == NULL) if (r == NULL)
r = nomem; r = ban_error_nomem;
return (r); return (r);
} }
void
BAN_Free_Errormsg(char *p)
{
if (p != ban_error_nomem)
free(p);
}
char * char *
BAN_Insert(struct ban *b) BAN_Insert(struct ban *b)
{ {
...@@ -1229,7 +1238,7 @@ ccf_ban(struct cli *cli, const char * const *av, void *priv) ...@@ -1229,7 +1238,7 @@ ccf_ban(struct cli *cli, const char * const *av, void *priv)
p = BAN_Insert(b); p = BAN_Insert(b);
if (p != NULL) { if (p != NULL) {
VCLI_Out(cli, "%s", p); VCLI_Out(cli, "%s", p);
free(p); BAN_Free_Errormsg(p);
VCLI_SetResult(cli, CLIS_PARAM); VCLI_SetResult(cli, CLIS_PARAM);
} }
} }
......
...@@ -446,7 +446,7 @@ VRT_ban_string(const struct vrt_ctx *ctx, const char *str) ...@@ -446,7 +446,7 @@ VRT_ban_string(const struct vrt_ctx *ctx, const char *str)
if (a1 != NULL) { if (a1 != NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, VSLb(ctx->vsl, SLT_VCL_Error,
"ban(): %s", a1); "ban(): %s", a1);
free(a1); BAN_Free_Errormsg(a1);
} }
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment