From 31249e6e59901768fe744bdc22ca4a843f00eb79 Mon Sep 17 00:00:00 2001 From: Tom Dewey Date: Fri, 9 Aug 2024 16:10:34 +0100 Subject: [PATCH] windows: ACH: Error handling cleanup --- .../acceleratedcryptographichash_cng.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/windows/acceleratedcryptographichash_cng.cpp b/src/windows/acceleratedcryptographichash_cng.cpp index dd28dc1..bd30256 100644 --- a/src/windows/acceleratedcryptographichash_cng.cpp +++ b/src/windows/acceleratedcryptographichash_cng.cpp @@ -29,7 +29,8 @@ struct AcceleratedCryptographicHash::impl { 0))) { qDebug() << "BCryptOpenAlgorithmProvider returned Error " << status; - goto Cleanup; + cleanup(); + return; } //calculate the size of the buffer to hold the hash object @@ -42,7 +43,8 @@ struct AcceleratedCryptographicHash::impl { 0))) { qDebug() << "BCryptGetProperty returned Error " << status; - goto Cleanup; + cleanup(); + return; } //allocate the hash object on the heap @@ -50,7 +52,8 @@ struct AcceleratedCryptographicHash::impl { if(NULL == pbHashObject) { qDebug() << "memory allocation failed"; - goto Cleanup; + cleanup(); + return; } //calculate the length of the hash @@ -63,7 +66,8 @@ struct AcceleratedCryptographicHash::impl { 0))) { qDebug() << "BCryptGetProperty returned Error " << status; - goto Cleanup; + cleanup(); + return; } //allocate the hash buffer on the heap @@ -92,7 +96,7 @@ struct AcceleratedCryptographicHash::impl { } ~impl() { - cleanup() + cleanup(); } void cleanup() { @@ -127,7 +131,8 @@ struct AcceleratedCryptographicHash::impl { 0))) { qDebug() << "BCryptHashData returned Error " << status; - goto Cleanup; + cleanup(); + return; } } @@ -145,7 +150,7 @@ struct AcceleratedCryptographicHash::impl { 0))) { qDebug() << "BCryptFinishHash returned Error " << status; - cleanup() + cleanup(); return {}; } else { // No cleanup required, as the dtor of this class will do so.