Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9149553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:29:34+00:00 2026-06-17T11:29:34+00:00

I have a structure: typedef struct { char *ptr; } A; And a map

  • 0

I have a structure:

typedef struct
{
char *ptr;
} A;

And a map

typedef std::map<std::wstring, A> myMap;

I have allocated memory for the ptr field using malloc while filling up the map.
To prevent memory leaks while clearing the map, I have the following code (actualMap is the actual map that I have to clear):

for (myMap::iterator iter = actualMap.begin(); iter != actualMap.end(); ++iter)
{
    Free((iter->second).ptr);
}
actualMap.clear();

However, when I start the application normally, I’m getting an exception while Free is being executed. This exception is not being generated when I start the application directly via VS2010.
Have I missed something?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:29:35+00:00Added an answer on June 17, 2026 at 11:29 am

    I recommend you use C++ std::string instead of raw pointer

    struct A
    { 
      std::wstring data;
    };
    
    std::map<std::wstring, A> myMap;
    
    actualMap.clear();
    

    A only has one pointer which points to string, so myMap can be:

    std::map<std::wstring, std::wstring> myMap;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure typedef struct store { char name[11]; int age; } store;
I have a structure: typedef struct stock { const char* key1p2; // stock code
I have following structure typedef struct List_Node { struct File_Descriptor *data; char *key; struct
I have a structure to represent strings in memory looking like this: typedef struct
I have a structure as below typedef struct Mystruct{ char *name; int telno; struct
I have the structure typedef struct EData { int a; char c; } Edata
I have this structure: typedef struct SM_DB { LIST_TYPE link; char name[SM_NAME_SIZE]; } SM_DB_TYPE;
I have the following structure typedef struct DeviceInfo { char[30] name; char[30] serial Number;
I have a structure: typedef struct { LogLevel level; char message[255]; } LogMessage; I
I have this structure : typedef struct xmlelem{ Char *Element_name; Char *Element_Text; pAttr_Element attr_arr[M];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.