Article ID: 000059846 Content Type: Product Information & Documentation Last Reviewed: 08/10/2021

How Should Object Memory be Freed Inside an Intel® Software Guard Extensions (Intel® SGX) Enclave?

BUILT IN - ARTICLE INTRO SECOND COMPONENT
Summary

Use the C++ operator "delete" to free object memory inside an enclave.

Description
  • Enclave includes C++ objects like classes and unique_ptrs.
  • Unable to determine how to free the memory for C++ objects in the enclave.
Resolution

Within enclaves, use the C++ delete operator to free memory that was previously allocated to classes, unique_ptrs, and other objects using the new operator. The operators new and delete behave the same within enclaves as they do in regular C++ applications.

Sample Code:

test.h:

class{

private:

  ClassA* ca;

  unique_ptr<ClassB> cb;

}

test.cpp:

//Use new to instantiate the class and unique_ptr objects

ca = new ClassA*(...); 

cb = make_unique<ClassB>(function(...));

//Use delete to free the memory previously allocated with new

delete ClassA;

delete cb;

 

Additional information

Refer to the C++ Language Support section in the Intel® Software Guard Extensions (Intel® SGX) SDK Developer Reference Guide for your operating system for more information.

Related Products

This article applies to 1 products