@@ -741,6 +741,7 @@ int qat_aes_gcm_cleanup(EVP_CIPHER_CTX *ctx)
741741#endif
742742 CpaStatus sts = 0 ;
743743 CpaCySymSessionSetupData * session_data = NULL ;
744+ CpaBoolean sessionInUse = CPA_FALSE ;
744745 int ret_val = 1 ;
745746
746747 DEBUG ("- Entering\n" );
@@ -764,48 +765,53 @@ int qat_aes_gcm_cleanup(EVP_CIPHER_CTX *ctx)
764765 return 0 ;
765766 }
766767
768+ /* Wait for in-flight requests before removing session */
769+ do {
770+ cpaCySymSessionInUse (qctx -> qat_ctx , & sessionInUse );
771+ } while (sessionInUse );
772+
767773 session_data = qctx -> session_data ;
768774 if (session_data ) {
769775 /* Remove the session */
770776 if (qctx -> qat_ctx ) {
771777 if ((sts = cpaCySymRemoveSession (qat_instance_handles [qctx -> inst_num ], qctx -> qat_ctx ))
772- != CPA_STATUS_SUCCESS ) {
778+ != CPA_STATUS_SUCCESS ) {
773779 WARN ("cpaCySymRemoveSession FAILED, sts = %d.!\n" , sts );
774780 ret_val = 0 ;
775781 /* Lets not return yet and instead make a best effort to
776782 * cleanup the rest to avoid memory leaks
777783 */
778784 }
779- qaeCryptoMemFreeNonZero (qctx -> qat_ctx );
785+ qaeCryptoMemFreeNonZero (qctx -> qat_ctx );
780786 qctx -> qat_ctx = NULL ;
781787 }
782- /* Cleanup the memory */
783- if (qctx -> aad ) {
784- qaeCryptoMemFreeNonZero (qctx -> aad );
785- qctx -> aad = NULL ;
786- }
787- if (qctx -> srcBufferList .pPrivateMetaData ) {
788- qaeCryptoMemFreeNonZero (qctx -> srcBufferList .pPrivateMetaData );
789- qctx -> srcBufferList .pPrivateMetaData = NULL ;
790- }
791- if (qctx -> dstBufferList .pPrivateMetaData ) {
792- qaeCryptoMemFreeNonZero (qctx -> dstBufferList .pPrivateMetaData );
793- qctx -> dstBufferList .pPrivateMetaData = NULL ;
794- }
795- if (qctx -> iv ) {
796- qaeCryptoMemFree (qctx -> iv );
797- qctx -> iv = NULL ;
798- }
799- if (qctx -> cipher_key ) {
800- qaeCryptoMemFree (qctx -> cipher_key );
801- qctx -> cipher_key = NULL ;
802- }
803- if (qctx -> OpData .pDigestResult ) {
804- qaeCryptoMemFree (qctx -> OpData .pDigestResult );
805- qctx -> OpData .pDigestResult = NULL ;
806- }
807- session_data -> cipherSetupData .pCipherKey = NULL ;
808- OPENSSL_clear_free (session_data , sizeof (CpaCySymSessionSetupData ));
788+ /* Cleanup the memory */
789+ if (qctx -> aad ) {
790+ qaeCryptoMemFreeNonZero (qctx -> aad );
791+ qctx -> aad = NULL ;
792+ }
793+ if (qctx -> srcBufferList .pPrivateMetaData ) {
794+ qaeCryptoMemFreeNonZero (qctx -> srcBufferList .pPrivateMetaData );
795+ qctx -> srcBufferList .pPrivateMetaData = NULL ;
796+ }
797+ if (qctx -> dstBufferList .pPrivateMetaData ) {
798+ qaeCryptoMemFreeNonZero (qctx -> dstBufferList .pPrivateMetaData );
799+ qctx -> dstBufferList .pPrivateMetaData = NULL ;
800+ }
801+ if (qctx -> iv ) {
802+ qaeCryptoMemFree (qctx -> iv );
803+ qctx -> iv = NULL ;
804+ }
805+ if (qctx -> cipher_key ) {
806+ qaeCryptoMemFree (qctx -> cipher_key );
807+ qctx -> cipher_key = NULL ;
808+ }
809+ if (qctx -> OpData .pDigestResult ) {
810+ qaeCryptoMemFree (qctx -> OpData .pDigestResult );
811+ qctx -> OpData .pDigestResult = NULL ;
812+ }
813+ session_data -> cipherSetupData .pCipherKey = NULL ;
814+ OPENSSL_clear_free (session_data , sizeof (CpaCySymSessionSetupData ));
809815 }
810816 qctx -> is_session_init = 0 ;
811817
0 commit comments