Skip to content

Commit

Permalink
Fix memory leak issue in Windows (#160)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiang, Hongyan <[email protected]>
  • Loading branch information
hyjiang authored Jul 27, 2023
1 parent 23b8b43 commit 9d223a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Windows/sgx/libsgx_tsgxssl/tw_critical_sec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ extern "C" {
}

if (sgx_thread_mutex_init(mutex, NULL) != 0) {
delete mutex;
errno = EINVAL;
FEND;
return 0;
Expand All @@ -88,10 +89,10 @@ extern "C" {
}
catch (std::bad_alloc e)
{
sgx_spin_unlock(&mutex_map_lock);
(void)e; // remove warning
if (p_mutex_dat != NULL) // second memory allocation failed
delete p_mutex_dat;
delete mutex;
errno = ENOMEM;
FEND;
return 0;
Expand Down Expand Up @@ -200,10 +201,12 @@ extern "C" {
}

// Free mutex and delete the mutex_it
mutex_count * p_mutex_count = it->second;
sgx_thread_mutex_t * mutex_it = it->second->mutex;

sgx_thread_mutex_destroy(mutex_it);
delete mutex_it;
delete p_mutex_count;

// delete the mutex_info_map entry
mutex_info_map.erase(it);
Expand All @@ -213,7 +216,4 @@ extern "C" {
FEND;
return;
}



}

0 comments on commit 9d223a6

Please sign in to comment.