[master] cb82537 Avoid a pointless strdup(), just return the vsb already.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Aug 16 11:20:15 CEST 2016
commit cb82537ddb9b5d982f8652cb71ef95cf54d2c2c7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Aug 15 17:17:37 2016 +0000
Avoid a pointless strdup(), just return the vsb already.
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index fdbaa00..6e416c4 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -83,7 +83,7 @@ static const char * const builtin_vcl =
static void __match_proto__(vsub_func_f)
run_vcc(void *priv)
{
- char *csrc;
+ struct vsb *csrc;
struct vsb *sb = NULL;
struct vcc_priv *vp;
int fd, i, l;
@@ -119,14 +119,14 @@ run_vcc(void *priv)
fprintf(stderr, "VCC cannot open %s", vp->csrcfile);
exit(2);
}
- l = strlen(csrc);
- i = write(fd, csrc, l);
+ l = VSB_len(csrc);
+ i = write(fd, VSB_data(csrc), l);
if (i != l) {
fprintf(stderr, "VCC cannot write %s", vp->csrcfile);
exit(2);
}
AZ(close(fd));
- free(csrc);
+ VSB_destroy(&csrc);
exit(0);
}
diff --git a/include/libvcc.h b/include/libvcc.h
index 2b69bd8..ad4bfdf 100644
--- a/include/libvcc.h
+++ b/include/libvcc.h
@@ -39,5 +39,5 @@ void VCC_Unsafe_Path(struct vcc *, unsigned);
void VCC_VCL_path(struct vcc *, const char *);
void VCC_VMOD_path(struct vcc *, const char *);
-char *VCC_Compile(struct vcc *, struct vsb **,
+struct vsb *VCC_Compile(struct vcc *, struct vsb **,
const char *vclsrc, const char *vclsrcfile);
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 22d8c10..fc6d346 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -545,14 +545,12 @@ vcc_resolve_includes(struct vcc *tl)
* Compile the VCL code from the given source and return the C-source
*/
-static char *
+static struct vsb *
vcc_CompileSource(struct vcc *tl, struct source *sp)
{
struct symbol *sym;
const struct var *v;
struct vsb *vsb;
-
- char *of;
int i;
vcc_Expr_Init(tl);
@@ -680,14 +678,7 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
VSB_cat(vsb, VSB_data(tl->fc));
AZ(VSB_finish(vsb));
-
- of = strdup(VSB_data(vsb));
- AN(of);
-
- VSB_destroy(&vsb);
-
- /* done */
- return (of);
+ return (vsb);
}
/*--------------------------------------------------------------------
@@ -695,12 +686,12 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
* formatted into the vsb.
*/
-char *
+struct vsb *
VCC_Compile(struct vcc *tl, struct vsb **sb,
const char *vclsrc, const char *vclsrcfile)
{
struct source *sp;
- char *r = NULL;
+ struct vsb *r = NULL;
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
AN(sb);
More information about the varnish-commit
mailing list