Fix memory leaks reported by Coverity accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix tizen_5.5_tv accepted/tizen/5.5/unified/20191031.022701 accepted/tizen/5.5/unified/mobile/hotfix/20201027.090440 accepted/tizen/unified/20191017.011726 submit/tizen/20191015.062638 submit/tizen_5.5/20191031.000004 submit/tizen_5.5_mobile_hotfix/20201026.185104 tizen_5.5.m2_release
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 14 Oct 2019 11:46:04 +0000 (13:46 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 15 Oct 2019 05:20:12 +0000 (07:20 +0200)
Change-Id: I88fc5c33eaf1596f1ae81f7d2728710f7a0c5b8d

src/vcore/api.cpp

index 7ecdb2a..918bdb1 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -800,18 +800,19 @@ err:
 
                if (result == 1 && checkCaFlag) { // check strictly
                        STACK_OF(X509) *resultChain = X509_STORE_CTX_get1_chain(&context);
-                       X509 *tmpCert = NULL;
-                       int caFlagValidity;
 
-                       while ((tmpCert = sk_X509_pop(resultChain))) {
-                               caFlagValidity = X509_check_ca(tmpCert);
+                       // the last one is not a CA.
+                       while (sk_X509_num(resultChain) > 1) {
+                               X509 *tmpCert = sk_X509_pop(resultChain);
+                               int caFlagValidity = X509_check_ca(tmpCert);
+                               X509_free(tmpCert);
 
-                               if (caFlagValidity != 1 && (tmpCert = sk_X509_pop(resultChain)) != NULL) {
-                                       // the last one is not a CA.
+                               if (caFlagValidity != 1) {
                                        result = 0;
                                        break;
                                }
                        }
+                       sk_X509_pop_free(resultChain, X509_free);
                }
 
                X509_STORE_CTX_cleanup(&context);