lib: Clean up potential memory leak

If sapi_ctx_init fails, free tcti_ctx

resolves: rhbz#1503959

Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
This commit is contained in:
Jerry Snitselaar 2017-10-19 00:34:52 -07:00
parent 16c073d093
commit 3d1352694e
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,31 @@
From 5b84837757cab93397cfa5830e69d2b7e7ce0e0c Mon Sep 17 00:00:00 2001
From: Jerry Snitselaar <jsnitsel@redhat.com>
Date: Wed, 18 Oct 2017 21:46:45 -0700
Subject: [PATCH] lib: clean up potential memory leak
In case where sapi_ctx_init fails in sapi_init_from_options, free tcti_ctx.
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
---
lib/context-util.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/context-util.c b/lib/context-util.c
index 7de22ac..c3034f9 100644
--- a/lib/context-util.c
+++ b/lib/context-util.c
@@ -205,8 +205,10 @@ sapi_init_from_options (common_opts_t *options)
if (tcti_ctx == NULL)
return NULL;
sapi_ctx = sapi_ctx_init (tcti_ctx);
- if (sapi_ctx == NULL)
+ if (sapi_ctx == NULL) {
+ free (tcti_ctx);
return NULL;
+ }
return sapi_ctx;
}
/*
--
2.15.0.rc0

View File

@ -1,6 +1,6 @@
Name: tpm2-tools Name: tpm2-tools
Version: 2.1.0 Version: 2.1.0
Release: 6%{?dist} Release: 7%{?dist}
Summary: A TPM2.0 testing tool build upon TPM2.0-TSS Summary: A TPM2.0 testing tool build upon TPM2.0-TSS
%global pkg_prefix tpm2.0-tools %global pkg_prefix tpm2.0-tools
@ -13,6 +13,8 @@ Source0: https://github.com/01org/tpm2.0-tools/archive/%{version}.tar.gz#/%{pkg_
Patch0: gcc7-implict-fallthrough-fix.patch Patch0: gcc7-implict-fallthrough-fix.patch
# https://github.com/01org/tpm2-tools/commit/5cee30cbc3da # https://github.com/01org/tpm2-tools/commit/5cee30cbc3da
Patch1: allow-to-build-with-openssl-1.1.x.patch Patch1: allow-to-build-with-openssl-1.1.x.patch
# https://github.com/01org/tpm2-tools/pull/567
Patch2: 0001-lib-clean-up-potential-memory-leak.patch
BuildRequires: gcc-c++ BuildRequires: gcc-c++
BuildRequires: libtool BuildRequires: libtool
@ -54,6 +56,9 @@ tpm2-tools is a batch of testing tools for tpm2.0. It is based on tpm2-tss.
%{_mandir}/man8/tpm2_*.8.gz %{_mandir}/man8/tpm2_*.8.gz
%changelog %changelog
* Thu Oct 19 2017 Jerry Snitselaar <jsnitsel@redhat.com> - 2.1.0-7
- Clean up potential memleak (RHBZ#1503959)
* Thu Oct 05 2017 Javier Martinez Canillas <javierm@redhat.com> - 2.1.0-6 * Thu Oct 05 2017 Javier Martinez Canillas <javierm@redhat.com> - 2.1.0-6
- Add tpm2-abrmd-devel BuildRequires so tools have abrmd support (RHBZ#1498909) - Add tpm2-abrmd-devel BuildRequires so tools have abrmd support (RHBZ#1498909)