diff options
author | Dariusz Michaluk <d.michaluk@samsung.com> | 2019-01-31 14:41:09 +0100 |
---|---|---|
committer | Krzysztof Jackiewicz <k.jackiewicz@samsung.com> | 2019-03-01 12:26:35 +0000 |
commit | b8bcaa92a0ea4d0edbcb6381051339a062923008 (patch) | |
tree | 16311a3af9fd96f5031c540d7c99a6883e201894 | |
parent | 6911e20f59b5804eea399017afc678653f0188f2 (diff) | |
download | key-manager-b8bcaa92a0ea4d0edbcb6381051339a062923008.tar.gz key-manager-b8bcaa92a0ea4d0edbcb6381051339a062923008.tar.bz2 key-manager-b8bcaa92a0ea4d0edbcb6381051339a062923008.zip |
Fix memory leak/corruption
Change-Id: I8f9bed07752fde26f629cca6931231dab5fd8980
-rw-r--r-- | src/manager/common/openssl-error-handler.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/manager/common/openssl-error-handler.cpp b/src/manager/common/openssl-error-handler.cpp index 40c3d2b4..e8649c10 100644 --- a/src/manager/common/openssl-error-handler.cpp +++ b/src/manager/common/openssl-error-handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017 - 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. @@ -33,6 +33,7 @@ #include <sstream> #include <string> #include <utility> +#include <vector> #define OPENSSL_SUCCESS 1 @@ -57,19 +58,19 @@ const char *ckm_debug_translate_error(int err) void errorDump() { - BIO *bio = BIO_new(BIO_s_mem()); - ERR_print_errors(bio); - char *buf = NULL; - long len = BIO_get_mem_data(bio, &buf); - if(len < 0) { - LogError("Fail in BIO_get_mem_data()"); + typedef std::unique_ptr<BIO, std::function<void(BIO *)>> BioUniquePtr; + BioUniquePtr bio(BIO_new(BIO_s_mem()), BIO_free_all); + if (!bio.get()) return; + + ERR_print_errors(bio.get()); + + std::vector<char> message(1024); + int len = BIO_read(bio.get(), message.data(), message.size()); + if (len > 0) { + message.resize(len); + LogError(std::string(message.begin(), message.end())); } - size_t length = static_cast<size_t>(len); - BIO_free(bio); - std::string ret(buf, length); - free(buf); - LogError(ret); } void errorHandle(const char *file, int line, const char *function, int openssl_ret) |