[master] 9755dc718 vcc: Plug inconsequential leak

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Jun 28 15:10:10 UTC 2023


commit 9755dc718e7946f873be9b32492fcda3dffa3c82
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Jun 28 15:22:43 2023 +0200

    vcc: Plug inconsequential leak
    
    The VCC_GlobalSymbol() function might be called twice for the same
    symbol. For example a subroutine symbol may be created when the sub
    keyword is first encountered, but it was referenced by a call action
    before the subroutine definition.
    
    The main problem the leak is causing is lsan's output polluting test
    cases looking at the screen output of varnishd, making the lines we
    care about scroll out to oblivion. To remedy this, VCC_GlobalSymbol()
    idempotence becomes free of side effects.

diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 1478509ed..3425c1c86 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -513,12 +513,22 @@ VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, vcc_ns_t ns, vcc_kind_t kind)
 void
 VCC_GlobalSymbol(struct symbol *sym, vcc_type_t type)
 {
+	vcc_kind_t kind;
 	struct vsb *vsb;
 
 	CHECK_OBJ_NOTNULL(sym, SYMBOL_MAGIC);
 	AN(type);
 	AN(type->global_pfx);
 
+	kind = VCC_HandleKind(type);
+
+	if (sym->lname != NULL) {
+		AN(sym->rname);
+		assert(sym->type == type);
+		assert(sym->kind == kind);
+		return;
+	}
+
 	vsb = VSB_new_auto();
 	AN(vsb);
 	VSB_printf(vsb, "%s_", type->global_pfx);
@@ -536,7 +546,7 @@ VCC_GlobalSymbol(struct symbol *sym, vcc_type_t type)
 	VSB_destroy(&vsb);
 
 	sym->type = type;
-	sym->kind = VCC_HandleKind(sym->type);
+	sym->kind = kind;
 	if (sym->kind != SYM_NONE) {
 		AZ(VCT_invalid_name(sym->rname, NULL));
 		if (type == SUB)


More information about the varnish-commit mailing list