Plug minor leaks for failures in vmod_vdp__init()

parent 3a3ae9bb
...@@ -581,6 +581,19 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e) ...@@ -581,6 +581,19 @@ vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
NEEDLESS(return (0)); NEEDLESS(return (0));
} }
static void
vdp_obj_free(VRT_CTX, struct VPFX(pipe_vdp) *vdp_obj)
{
free(vdp_obj->argv);
if (ctx != NULL && vdp_obj->vdp != NULL)
VRT_RemoveFilter(ctx, NULL, vdp_obj->vdp);
free(TRUST_ME(vdp_obj->vdp->name));
free(vdp_obj->vdp);
free(vdp_obj->path);
free(vdp_obj->name);
FREE_OBJ(vdp_obj);
}
/* vdp object */ /* vdp object */
VCL_VOID VCL_VOID
...@@ -637,7 +650,6 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, ...@@ -637,7 +650,6 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
obj_name, VAS_errtxt(errno)); obj_name, VAS_errtxt(errno));
return; return;
} }
*vdpp = vdp_obj;
vdp_obj->name = strdup(obj_name); vdp_obj->name = strdup(obj_name);
vdp_obj->path = strdup(path); vdp_obj->path = strdup(path);
vdp_obj->bufsz = bufsz; vdp_obj->bufsz = bufsz;
...@@ -649,6 +661,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, ...@@ -649,6 +661,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
if (vdp == NULL) { if (vdp == NULL) {
VDPFAIL(ctx, "new %s: cannot allocate space for VDP: %s", VDPFAIL(ctx, "new %s: cannot allocate space for VDP: %s",
obj_name, VAS_errtxt(errno)); obj_name, VAS_errtxt(errno));
vdp_obj_free(NULL, vdp_obj);
return; return;
} }
vdp->name = strdup(vdp_name); vdp->name = strdup(vdp_name);
...@@ -658,6 +671,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, ...@@ -658,6 +671,7 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
// XXX free mem etc // XXX free mem etc
if (VRT_AddFilter(ctx, NULL, vdp)) { if (VRT_AddFilter(ctx, NULL, vdp)) {
vdp_obj_free(NULL, vdp_obj);
return; return;
} }
vdp_obj->vdp = vdp; vdp_obj->vdp = vdp;
...@@ -667,24 +681,29 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name, ...@@ -667,24 +681,29 @@ vmod_vdp__init(VRT_CTX, struct VPFX(pipe_vdp) **vdpp, const char *obj_name,
if (map == NULL) { if (map == NULL) {
VDPFAIL(ctx, "new %s: cannot allocate space for map entry: %s", VDPFAIL(ctx, "new %s: cannot allocate space for map entry: %s",
obj_name, VAS_errtxt(errno)); obj_name, VAS_errtxt(errno));
vdp_obj_free(ctx, vdp_obj);
return; return;
} }
map->vdp = vdp;
map->vcl = ctx->vcl;
map->obj = vdp_obj;
AZ(VRBT_INSERT(vdp_tree, &tree_h, map));
errno = 0; errno = 0;
vdp_obj->argv = malloc(2 * sizeof(*vdp_obj->argv)); vdp_obj->argv = malloc(2 * sizeof(*vdp_obj->argv));
if (vdp_obj->argv == NULL) { if (vdp_obj->argv == NULL) {
VDPFAIL(ctx, "new %s: cannot allocate argv: %s", obj_name, VDPFAIL(ctx, "new %s: cannot allocate argv: %s", obj_name,
VAS_errtxt(errno)); VAS_errtxt(errno));
FREE_OBJ(map);
vdp_obj_free(ctx, vdp_obj);
return; return;
} }
vdp_obj->argv[0] = vdp_obj->path; vdp_obj->argv[0] = vdp_obj->path;
vdp_obj->argv[1] = NULL; vdp_obj->argv[1] = NULL;
vdp_obj->argc = 1; vdp_obj->argc = 1;
map->vdp = vdp;
map->vcl = ctx->vcl;
map->obj = vdp_obj;
AZ(VRBT_INSERT(vdp_tree, &tree_h, map));
*vdpp = vdp_obj;
return; return;
} }
......
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