The function dkim_options, when used with DKIM_OPTS_SKIPHDRS or DKIM_OPTS_SIGNHDRS, can produce a memory leak. For example:
dkim_options(dkim_lib, DKIM_OP_SETOPT, DKIM_OPTS_SKIPHDRS, dkim_skip_headers, sizeof(char **));
Later, after calling dkim_close(), memory is not freed. The problem appears to be that dkim_options compiles regex's using regcomp() without later freeing them. If you call the following before dkim_close(), the memory is freed:
dkim_options(dkim_lib, DKIM_OP_SETOPT, DKIM_OPTS_SKIPHDRS, NULL, sizeof(char **));
This is because dkim_options with a NULL ptr value calls regfree(). The attached patch calls regfree() during dkim_close() on any regexes that were compiled for DKIM_OPTS_SKIPHDRS or DKIM_OPTS_SIGNHDRS.