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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:07:01+00:00 2026-06-03T08:07:01+00:00

I get a segmentation fault at this point of code when calling auto_ptr release

  • 0

I get a segmentation fault at this point of code when calling auto_ptr release member:

try
{
    newMod->init(params);
}
catch (const std::exception& e)
{
#ifndef CONFIG_STATIC
    dlclose(handle);
#endif
    throw std::runtime_error(utils::buildString(
            "%s: Error initializing module %s: %s",
            DBG_FUNC_NAME, newMod->name().c_str(), e.what()));
}

_modules.insert(std::make_pair(newMod->name(), newMod.release()));

Where _modules is

std::map<std::string, IModule*> _modules;

and newMod is

std::auto_ptr<IModule> newMod(0);

later reset with a proper pointer value. I know the pointer to IModule is valid, because I’m calling the init member before release.

This:

_modules.insert(std::make_pair(newMod->name(), newMod.get()));
newMod.release();

works perfectly well and this is what gdb says:

#0  _M_rep (this=0xbfe8e908, __str=...) at /usr/src/debug/gcc-4.5.1-20101208/obj-i586-suse-linux/i586-suse-linux/libstdc++-v3/include/bits/basic_string.h:287
#1  std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (this=0xbfe8e908, __str=...)
at /usr/src/debug/gcc-4.5.1-20101208/obj-i586-suse-linux/i586-suse-linux/libstdc++-v3/include/bits/basic_string.tcc:173
#2  0x0805d76f in sm::core::mod::ModuleManager::loadModule (this=0x8074768, name=..., params=...) at src/core/ModuleManager.cpp:150
#3  0x08056edb in sm::core::Main::start (this=0xbfe8e9e0) at src/core/Main.cpp:82
#4  0x08055131 in main (argc=4, argv=0xbfe8ebf4) at src/core/smmain.cpp:15

and the line it segfaults on is:

{ return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }

Any idea on what could be wrong in this one?

  • 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-03T08:07:03+00:00Added an answer on June 3, 2026 at 8:07 am
    _modules.insert(std::make_pair(newMod->name(), newMod.release()));
    

    The order of evaluation of arguments to a function is not defined by the standard. An implementation can evaluate newMod.release() before newMod->name(), which would make that second call invalid.


    Side note: auto_ptr is deprecated in C++11 (Annex D.10 in draft n3290):

    The class template auto_ptr is deprecated. [ Note: The class template unique_ptr (20.7.1) provides a better solution. — end note ]

    If you have access to that, and the time/resource to do so, consider switch to the newer smart pointer classes.

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

Sidebar

Related Questions

I get a segmentation fault when running this code. Anyone know why? Thanks. #include
I get Segmentation Fault when I try to run my program. Can someone please
In the following code I get a segmentation fault: Set *getpar() {...} char function(...)
One obvious way to cause a stack overflow and get Segmentation fault would be
Anytime I call cvNamedWindow I get a segmentation fault and I don't know why
In the following: printf(Example%s\n,NULL); printf(%s\n,NULL); I get the output as: Example(null) Segmentation Fault When
I get a segmentation fault when iterating over a set. The stack trace points
I'm stuck and can't figure out why I get a segmentation fault. When I
I am getting a segmentation fault in the following code: void print_stack(Node * root)
I am receiving a Segmentation Fault error when I run this program. To summarize,

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.