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 6111025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:35:00+00:00 2026-05-23T14:35:00+00:00

I am using bcc32 command line compiler from Borland Embarcadero. Consider this program: int

  • 0

I am using bcc32 command line compiler from Borland Embarcadero. Consider this program:

    int main(int, char **)
    {
        try
        {
            std::string *a = new string(0xf0000000, ' ');
            ...
            delete a;
        }
        catch(const std::bad_alloc &)
        {
            ...
        }
    }

When the std::string constructor throws a memory exception, the stack is unwound and control is passed to the catch-block. Gnu compilers build in code to delete the memory allocated for the std::string object ‘auto-magically’, as was stated by someone who commented on the answer in Who deletes the memory allocated during a "new" operation which has exception in constructor? which I wrote. I ran the program in http://ideone.com/IRxHX and the result is that nobody frees the memory allocated by ‘operator new’ if an exception is thrown before the result of ‘new’ is stored in an lvalue. In the above case the variable ‘a’.

Questions are:
1 Is there a way to delete the memory generated by ‘new’ in case of an exception, as a part of the stack unwind procedure?
2 What does the C++ standard demand from compilers in this case

  • 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-05-23T14:35:00+00:00Added an answer on May 23, 2026 at 2:35 pm

    Either your compiler is broken, or something else funny is going on. The implementation is required to free the memory:

    5.3.4/17:

    If any part of the object initialization described above terminates by
    throwing an exception and a suitable deallocation function can be
    found, the deallocation function is called to free the memory in which
    the object was being constructed, after which the exception continues
    to propagate in the context of the new- expression. If no unambiguous
    matching deallocation function can be found, propagating the exception
    does not cause the object’s memory to be freed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I configure Vim to compile C code using Borland’s compiler
Does anyone know what the command line option is to generate a preprocessed file
I'm using the line below to have MSBuild build a Delphi 2010 groupproj: MSBuild
Using jQuery's UI Tabs. This is my code. <div id=tabs> <ul> <li><a href=#tabs-1>Find a
I am attempting to pull some information from my tnsnames file using regex. I
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have

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.