Skip to content

Commit 75e9879

Browse files
authored
Merge pull request #530 from Zha0Chan/main
Fix start_auth_session resource leak
2 parents 1411c46 + 438b8f0 commit 75e9879

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

tss-esapi/src/abstraction/ak.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ pub fn load_ak(
122122
.with_decrypt(true)
123123
.with_encrypt(true)
124124
.build();
125-
context.tr_sess_set_attributes(
126-
policy_auth_session,
127-
session_attributes,
128-
session_attributes_mask,
129-
)?;
125+
context
126+
.tr_sess_set_attributes(
127+
policy_auth_session,
128+
session_attributes,
129+
session_attributes_mask,
130+
)
131+
.or_else(|e| {
132+
context.flush_context(SessionHandle::from(policy_auth_session).into())?;
133+
Err(e)
134+
})?;
130135

131136
let key_handle = context.execute_with_temporary_object(
132137
SessionHandle::from(policy_auth_session).into(),
@@ -182,11 +187,16 @@ pub fn create_ak<IKC: IntoKeyCustomization>(
182187
.with_decrypt(true)
183188
.with_encrypt(true)
184189
.build();
185-
context.tr_sess_set_attributes(
186-
policy_auth_session,
187-
session_attributes,
188-
session_attributes_mask,
189-
)?;
190+
context
191+
.tr_sess_set_attributes(
192+
policy_auth_session,
193+
session_attributes,
194+
session_attributes_mask,
195+
)
196+
.or_else(|e| {
197+
context.flush_context(SessionHandle::from(policy_auth_session).into())?;
198+
Err(e)
199+
})?;
190200

191201
context.execute_with_temporary_object(
192202
SessionHandle::from(policy_auth_session).into(),

tss-esapi/src/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ impl Context {
305305
.with_decrypt(true)
306306
.with_encrypt(true)
307307
.build();
308-
self.tr_sess_set_attributes(auth_session, session_attributes, session_attributes_mask)?;
308+
self.tr_sess_set_attributes(auth_session, session_attributes, session_attributes_mask)
309+
.or_else(|e| {
310+
self.flush_context(SessionHandle::from(auth_session).into())?;
311+
Err(e)
312+
})?;
309313

310314
let res = self.execute_with_session(Some(auth_session), f);
311315

0 commit comments

Comments
 (0)