From b8bcaa92a0ea4d0edbcb6381051339a062923008 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Thu, 31 Jan 2019 14:41:09 +0100 Subject: [PATCH] Fix memory leak/corruption Change-Id: I8f9bed07752fde26f629cca6931231dab5fd8980 --- src/manager/common/openssl-error-handler.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/manager/common/openssl-error-handler.cpp b/src/manager/common/openssl-error-handler.cpp index 40c3d2b..e8649c1 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 #include #include +#include #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> BioUniquePtr; + BioUniquePtr bio(BIO_new(BIO_s_mem()), BIO_free_all); + if (!bio.get()) return; + + ERR_print_errors(bio.get()); + + std::vector 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(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) -- 2.7.4