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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:16:06+00:00 2026-06-16T04:16:06+00:00

Give the following function: osal_allocator* SharedMemoryManager::allocator();I Where osal_allocator is a ‘c’ structure, containing function

  • 0

Give the following function:

osal_allocator* SharedMemoryManager::allocator();I  

Where osal_allocator is a ‘c’ structure, containing function pointers.

And the a wrapper class that provides the following constructor:

Allocator::Allocator( osal_allocator* );

A function makes the following call:

001 SomeFunc( SharedMemoryManager* shm )
002 {
003    Allocator myAllocator = shm.allocator();
004
005    myAllocator.doSomething();
006
007    // stuff
008 }

The code fails with a SIG SEGV. The reason is that on line 003 the destructor for myAllocator is called immediately after its constructor is called. This means that myAllocator is invalid on line 005, since it has been destroyed.

(Note: the default constructor is not being called and neither are any assignment operators).

If line 003 is changed to:

003    Allocator myAllocator( shm.allocator );

The function works as expected, with myAllocators‘s destructor not being called until it goes out of scope.

Unfortunately I have not been able to reproduce this issue with a simple example.

I am using :

g++ (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3)

With the following options:

c++ -MD -D__LINUX__  -g -ansi -Wall -Wextra -Wformat -Wno-format-security -Woverloaded-virtual -Iinc

Why is the compiler generating a destructor call for the first example

  • 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-16T04:16:07+00:00Added an answer on June 16, 2026 at 4:16 am

    With this line

    Allocator myAllocator = shm.allocator();
    

    You are doing the following operations:

    1. Construct a new Allocator temporary object
    2. Call the copy constructor of Allocator where the rhs is the temporary
    3. Destroy the temporary object created at point 1

    There are two possible operations which you din’t consider and that may cause the SIG SEV: copy constructor and destructor.

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

Sidebar

Related Questions

I use the following Javascript function.It will not work.It will give the Undefined Error
I am confused with following string function echo strlen(l\n2); //give 3 in output where
I tried the following, all of which fail on function ScrollIntoView and give a
Why does the following give no compilation error?: // T.h template<class T> class X
Why does the following code give me an error (g++ 4.1.2)? template<class A> class
I have the following Javascript function that makes a call to an Asp.Net WebMethod
I have the following function that I wrote function range_gen($num1,$num2){ $exp = explode('.',$num1); $accuracy
I created a class A and wrote the following function foo() class A {
I have the following function that is suppose to take a value from a
I have the following function that finds values within a HTML DOM ; It

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.