Skip to content

Commit 9d223a6

Browse files
authored
Fix memory leak issue in Windows (#160)
Signed-off-by: Jiang, Hongyan <[email protected]>
1 parent 23b8b43 commit 9d223a6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Windows/sgx/libsgx_tsgxssl/tw_critical_sec.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extern "C" {
7878
}
7979

8080
if (sgx_thread_mutex_init(mutex, NULL) != 0) {
81+
delete mutex;
8182
errno = EINVAL;
8283
FEND;
8384
return 0;
@@ -88,10 +89,10 @@ extern "C" {
8889
}
8990
catch (std::bad_alloc e)
9091
{
91-
sgx_spin_unlock(&mutex_map_lock);
9292
(void)e; // remove warning
9393
if (p_mutex_dat != NULL) // second memory allocation failed
9494
delete p_mutex_dat;
95+
delete mutex;
9596
errno = ENOMEM;
9697
FEND;
9798
return 0;
@@ -200,10 +201,12 @@ extern "C" {
200201
}
201202

202203
// Free mutex and delete the mutex_it
204+
mutex_count * p_mutex_count = it->second;
203205
sgx_thread_mutex_t * mutex_it = it->second->mutex;
204206

205207
sgx_thread_mutex_destroy(mutex_it);
206208
delete mutex_it;
209+
delete p_mutex_count;
207210

208211
// delete the mutex_info_map entry
209212
mutex_info_map.erase(it);
@@ -213,7 +216,4 @@ extern "C" {
213216
FEND;
214217
return;
215218
}
216-
217-
218-
219219
}

0 commit comments

Comments
 (0)