CertCloseStore is called with flag CERT_CLOSE_STORE_FORCE_FLAG.

This flag forces CertCloseStore to free memory for all contexts associated with the store. This flag can be safely used only when the store is opened in a function and neither the store handle nor any of its contexts are passed to any called functions.

To force the freeing of memory for all contexts associated with a store, set CERT_STORE_CLOSE_FORCE_FLAG. With this flag set, memory for all contexts associated with the store is freed and all pointers to certificate, CRL, or CTL contexts associated with the store become invalid. This flag should only be set when the store is opened in a function and neither the store handle nor any of its contexts were ever passed to any called functions.

The above points are directly referenced from the MSDN link stated below.

An ideal call to CertCloseStore should be:

CertCloseStore(hCertStore, 0); // This does not force close the store if the store is already closed.

Reference:

http://msdn.microsoft.com/en-us/library/aa376026(VS.85).aspx

 

- Shamik Misra