Jump to content
sumit_tuwien

Safely remove malloc in SystemC

Recommended Posts

We have discovered C-style dynamic memory allocation in following files:

 


   utils/sc_report.cpp
   utils/sc_hash.cpp
   utils/sc_report_handler.cpp
   utils/sc_mempool.cpp

 

 

However, dynamic memory allocation for other C++ files have been done using C++ style new/delete.
 
Our question: Can we replace them safely with new/delete or we will see some surprises ?
 
In fact it seems they are legacy codes taken from somewhere and we can replace them safely. Example (utils/sc_report.cpp)
 
 

 

............
............
static char empty_str[] = "";
static inline char * empty_dup(const char * p)
{
    if ( p && *p )
    {
        char* result;
        result = (char*)malloc(strlen(p)+1); // Very very legacy C style
        strcpy(result, p);
        return result;
    }
    else
    {
        return empty_str;
    }
}


............
............

 

 

 
Regards, Sumit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×