A function that builds a parity leaks references. Fix the leak.
Every node has a reference count: Cudd_Ref adds one and Cudd_RecursiveDeref removes one, and CUDD may free a node only once its count is 0. A leak is a reference that is taken and never released, so its node can never be freed. Cudd_CheckZeroRef finds it: after the program has released everything, it counts the nodes still referenced.
Cudd_Ref
Cudd_RecursiveDeref
Cudd_CheckZeroRef
A program computes t = Cudd_bddAnd(dd, x0, x1) and references it, then u = Cudd_bddOr(dd, t, x2) and references it, and at the end releases u once.
t = Cudd_bddAnd(dd, x0, x1)
u = Cudd_bddOr(dd, t, x2)
u
Follow each reference: u's is released, but the one taken for t, the BDD of x0 & x1, never is.
t
x0 & x1
Cudd_CheckZeroRef then counts the node of x0 & x1. Releasing t once u is built removes the leak, and u, which is x0 & x1 | x2, is unchanged.
x0 & x1 | x2
Each reference taken needs exactly one release, on every path through the program.
The function in the editor builds the parity of x[0] to x[n - 1]: 1 when an odd number of them are 1. It computes the right function, but it leaks: after its caller releases the result, Cudd_CheckZeroRef still finds referenced nodes.
x[0]
x[n - 1]
Fix it, keeping its name and parameters.
A C file that includes cudd.h and defines parity with its name and parameters unchanged; the caller releases the result. The check compiles your file with a hidden test program against CUDD 3.0.0, runs it with AddressSanitizer and UndefinedBehaviorSanitizer, and says which test failed.
cudd.h
parity
parity(dd, x, n) returns the parity of x[0] to x[n - 1], referenced.
No reference leaked: Cudd_CheckZeroRef reports 0.
Watch the conditions: the first waits until the file defines parity; the values and the references are decided when you press Check answer.
Trace the loop for n = 2 by hand, as the example traces its lines: list each BDD created, each Cudd_Ref and each release.
n = 2
At the end of your trace, exactly one reference should be left, on the result the caller receives.
Kata 5.4 of Binary Decision Diagrams with CUDD on formal.org. The site checks the answer when you press Check answer; sign in to keep your progress.