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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:49:21+00:00 2026-05-16T01:49:21+00:00

I believe the following causes a memory access violation error as the false parameter

  • 0

I believe the following causes a memory access violation error as the false parameter (fcopy) causes the memory to be released for the CComBSTR:

CComBSTR myCComBSTR;
string strMyCComBSTR = string(_bstr_t(myCComBSTR, false));

However, I’m not quite sure why this is as the MSDN documentation says the following about fcopy:

If false, the bstr argument is
attached to the new object without
making a copy by calling
SysAllocString.

My question is:

  1. Am I right in saying that this is a problem
  2. If so – why?

Thanks

  • 1 1 Answer
  • 1 View
  • 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-16T01:49:21+00:00Added an answer on May 16, 2026 at 1:49 am

    Yes, this is a problem – both myCComBSTR and the temporary will try to free the string since they both will think they own it.

    You see, fcopy having value of false means “please don’t duplicate the string body, just attach to the body I give you”. When the first line completes you have myCComBSTR owning the string buffer and when the temporary object on the second line is created it also takes ownership of the same string buffer because of fcopy being false. Then the temporary is destroyed and frees the string buffer. Later myCComBSTR will be destroyed and will try to free the same string buffer again – you run into so-called double free which induces undefined behavior.

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

Sidebar

Related Questions

I believe I am having a memory issue using numpy arrays. The following code
EDIT: OK, I believe the following solutions are valid: Use the jQuery AOP plugin.
I can't believe that the following statement seems to be still true So, I
I cant believe fastest solution for a multilined JLabel is the following one (text
I have the following function sending an email twice (and I believe running if($result)
I have the following two queries, I believe that the one that uses the
I can't believe how unbelievably complicated this has been... I have the following XML...
In the following two cases, if Customer is disposable (implementing IDisposable), I believe it
I believe I am doing the following: var myQuery = Products.Where( p => p.deptid
I believe I have memory leak with some of my code that uses the

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.