Re: [libopendkim] dkim_init() and dkim_close() thread problems

From: Murray S. Kucherawy <>
Date: Fri, 30 Apr 2010 07:52:03 -0700 (PDT)

I think I see what's up here.

You need to call dkim_init() once before your program becomes
multi-threaded, and dkim_close() once when the application is shutting
down. Then, in each thread, you call dkim_sign() or dkim_verify() to set
up one of those operations, and dkim_free() to terminate them.

The way you're doing it causes dkim_init() to initialize the OpenSSL
library (libcrypto) over and over, and dkim_close() to shut that library
down; specifically, it has some thread management stuff that gets set up
by dkim_init() and destroyed by dkim_close(). So if something like the
following happens, you'll get a crash:

Thread #1 calls dkim_init()
Thread #2 calls dkim_init()
Thread #2 runs all of its operations
Thread #2 calls dkim_close()
Thread #1 tries to do something that requires a libcrypto function
Thread #1 hits data in libcrypto that has been free()d already by thread #2

And you're also right that two threads in those functions could race into
the libcrypto setup/shutdown operations and step on each other, but that's
not the only problem with the way you're using the library.

Let me know if that works.

Received on Fri Apr 30 2010 - 14:52:22 PST

This archive was generated by hypermail 2.3.0 : Mon Oct 29 2012 - 23:19:47 PST