Is there a limit to the number of contexts a single program can (re)create? libcuda.so segfault crea

I have written some CUDA code using the driver API and am using CUnit to test it. In order not to let one failed test affect the results of the others I create a new context for each test, destroying it when the test is over. My unit testing program crashes with a segfault within libcuda.so at the same point every time when running a full suite. If I disable the test that fails then the test immediately following crashes with the same error. Running the tests individually, one per program invocation, does not crash. This has led me to believe that there may be a limit to the number of contexts a single program can create. The other possibility is that the program attempts to create a new context before the CUDA library/nVidia driver has finished cleaning up the old context. Does anyone have any more information on whether this might be the case?

The crash occurs within cuModuleGetFunction which is the second CUDA driver API call following cuCtxCreate (the first being cuModuleLoadData) so the crash would appear to be asynchronous (perhaps caused by the lazy allocation of resources when loading a module into the new context). I have compiled the program with various compilers (ICC 12.0.5, GCC 4.4.6, GCC 4.6.1) all with the same result. I am using CUDA toolkit version 4.0 with driver version 275.09.07.