matcher: Support duplicate elements in a chain

When freeing up a chain, handle duplicate elements gracefully, and don't
free them twice.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>