Quantcast

[shared_ptr] make_shared causes Access Violation

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[shared_ptr] make_shared causes Access Violation

Paul Heil
I have a Visual Studio 2008 C++ application for ARMV4I Windows Mobile 6 where I'm using `boost::shared_ptr<>` to manage a fairly large object (4KB). Unfortunately, `boost::make_shared<>` causes an Access Violation exception. I am using Boost 1.45.0 with STLPort 5.2.1.

My code:

    struct Foo
    {
        char a[ 4 * 1024 - 1 ];
    };

    int _tmain( int argc, _TCHAR* argv[] )
    {
        boost::shared_ptr< Foo > f = boost::make_shared< Foo >(); // Access Violation
        return 0;
    }

The exception callstack:

    test.exe!boost::detail::sp_ms_deleter<o>::sp_ms_deleter<o>(void) Line: 60, Byte Offsets: 0x18    C++
    test.exe!boost::make_shared<o>(void) Line: 106, Byte Offsets: 0x5c    C++
    test.exe!wmain(int argc = 1, wchar_t** argv = 0x01b40060) Line: 81, Byte Offsets: 0x18    C++
    test.exe!mainWCRTStartup(HINSTANCE__* hInstance = 0x00000003, HINSTANCE__* hInstancePrev = 0x00000000, unsigned short* lpszCmdLine = 0x00000003, int nCmdShow = 0) Line: 188, Byte Offsets: 0x94    C++

The location of the exception (boost\smart_ptr\make_shared.hpp):

    template< class T > class sp_ms_deleter
    {
        /* snip! */       
    public:
        sp_ms_deleter(): initialized_( false )
        {    // line: 60  this = NULL
        }

        /* snip! */

This issue does not occur when compiling for x86 Windows. This issue also does not occur when using the shared_ptr like this:

    boost::shared_ptr< Foo > f1 = boost::shared_ptr< Foo >( new Foo );

Can anybody explain what's going on and why this is breaking only on ARMV4I Windows Mobile 6?

Thanks,
PaulH

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Krzysztof Czainski
2011/5/10 Paul Heil <[hidden email]>
I have a Visual Studio 2008 C++ application for ARMV4I Windows Mobile 6 where I'm using `boost::shared_ptr<>` to manage a fairly large object (4KB). Unfortunately, `boost::make_shared<>` causes an Access Violation exception. I am using Boost 1.45.0 with STLPort 5.2.1.

My code:

    struct Foo
    {
        char a[ 4 * 1024 - 1 ];
    };

    int _tmain( int argc, _TCHAR* argv[] )
    {
        boost::shared_ptr< Foo > f = boost::make_shared< Foo >(); // Access Violation
        return 0;
    }

The exception callstack:

    test.exe!boost::detail::sp_ms_deleter<o>::sp_ms_deleter<o>(void) Line: 60, Byte Offsets: 0x18    C++
    test.exe!boost::make_shared<o>(void) Line: 106, Byte Offsets: 0x5c    C++
    test.exe!wmain(int argc = 1, wchar_t** argv = 0x01b40060) Line: 81, Byte Offsets: 0x18    C++
    test.exe!mainWCRTStartup(HINSTANCE__* hInstance = 0x00000003, HINSTANCE__* hInstancePrev = 0x00000000, unsigned short* lpszCmdLine = 0x00000003, int nCmdShow = 0) Line: 188, Byte Offsets: 0x94    C++

The location of the exception (boost\smart_ptr\make_shared.hpp):

    template< class T > class sp_ms_deleter
    {
        /* snip! */       
    public:
        sp_ms_deleter(): initialized_( false )
        {    // line: 60  this = NULL
        }

        /* snip! */

This issue does not occur when compiling for x86 Windows. This issue also does not occur when using the shared_ptr like this:

    boost::shared_ptr< Foo > f1 = boost::shared_ptr< Foo >( new Foo );

Can anybody explain what's going on and why this is breaking only on ARMV4I Windows Mobile 6?

Thanks,
PaulH

My guess: stack overflow. If I remember correctly, 2 times sizeof( Foo ) must fit on the stack when using make_shared.

Regards,
Kris

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Paul Heil
I can declare two instances of Foo with no error:

    int _tmain( int argc, _TCHAR* argv[] )
    {
        Foo a;
        Foo b;
        return 0;
    }

The linker options I'm using are /STACK 65536,4096. So, the stack should be capable of handling 16 times sizeof( Foo ).

-PaulH

On Tue, May 10, 2011 at 3:17 PM, Krzysztof Czainski <[hidden email]> wrote:
2011/5/10 Paul Heil <[hidden email]>
I have a Visual Studio 2008 C++ application for ARMV4I Windows Mobile 6 where I'm using `boost::shared_ptr<>` to manage a fairly large object (4KB). Unfortunately, `boost::make_shared<>` causes an Access Violation exception. I am using Boost 1.45.0 with STLPort 5.2.1.

My code:

    struct Foo
    {
        char a[ 4 * 1024 - 1 ];
    };

    int _tmain( int argc, _TCHAR* argv[] )
    {
        boost::shared_ptr< Foo > f = boost::make_shared< Foo >(); // Access Violation
        return 0;
    }

The exception callstack:

    test.exe!boost::detail::sp_ms_deleter<o>::sp_ms_deleter<o>(void) Line: 60, Byte Offsets: 0x18    C++
    test.exe!boost::make_shared<o>(void) Line: 106, Byte Offsets: 0x5c    C++
    test.exe!wmain(int argc = 1, wchar_t** argv = 0x01b40060) Line: 81, Byte Offsets: 0x18    C++
    test.exe!mainWCRTStartup(HINSTANCE__* hInstance = 0x00000003, HINSTANCE__* hInstancePrev = 0x00000000, unsigned short* lpszCmdLine = 0x00000003, int nCmdShow = 0) Line: 188, Byte Offsets: 0x94    C++

The location of the exception (boost\smart_ptr\make_shared.hpp):

    template< class T > class sp_ms_deleter
    {
        /* snip! */       
    public:
        sp_ms_deleter(): initialized_( false )
        {    // line: 60  this = NULL
        }

        /* snip! */

This issue does not occur when compiling for x86 Windows. This issue also does not occur when using the shared_ptr like this:

    boost::shared_ptr< Foo > f1 = boost::shared_ptr< Foo >( new Foo );

Can anybody explain what's going on and why this is breaking only on ARMV4I Windows Mobile 6?

Thanks,
PaulH

My guess: stack overflow. If I remember correctly, 2 times sizeof( Foo ) must fit on the stack when using make_shared.

Regards,
Kris

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Peter Dimov-5
In reply to this post by Krzysztof Czainski
Krzysztof Czainski wrote:
> My guess: stack overflow. If I remember correctly, 2 times sizeof( Foo )
> must fit on the stack when using make_shared.

Yes, this is ticket #4256:

https://svn.boost.org/trac/boost/ticket/4256

It should be fixed in the latest version (1.46).

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Paul Heil
I have upgraded to boost 1.46.1. The issue remains the same.

-PaulH

On Tue, May 10, 2011 at 4:05 PM, Peter Dimov <[hidden email]> wrote:
Krzysztof Czainski wrote:
My guess: stack overflow. If I remember correctly, 2 times sizeof( Foo ) must fit on the stack when using make_shared.

Yes, this is ticket #4256:

https://svn.boost.org/trac/boost/ticket/4256

It should be fixed in the latest version (1.46).
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Peter Dimov-5
Paul Heil wrote:

> I have upgraded to boost 1.46.1. The issue remains the same.

Can you please post the new call stack?
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Paul Heil
The callstack is the same with boost 1.46.1.

    test.exe!boost::detail::sp_ms_deleter<o>::sp_ms_deleter<o>(void) Line: 60, Byte Offsets: 0x18    C++
    test.exe!boost::make_shared<o>(void) Line: 106, Byte Offsets: 0x5c    C++
    test.exe!wmain(int argc = 1, wchar_t** argv = 0x01b400b0) Line: 37, Byte Offsets: 0x1c    C++
    test.exe!mainWCRTStartup(HINSTANCE__* hInstance = 0x002608d0, HINSTANCE__* hInstancePrev = 0x00000000, unsigned short* lpszCmdLine = 0x002608d0, int nCmdShow = 0) Line: 188, Byte Offsets: 0x94    C++



On Tue, May 10, 2011 at 5:15 PM, Peter Dimov <[hidden email]> wrote:
Paul Heil wrote:

I have upgraded to boost 1.46.1. The issue remains the same.

Can you please post the new call stack?

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Peter Dimov-5
Paul Heil wrote:

> The callstack is the same with boost 1.46.1.

Yes, you're right, sorry. The fix is not in 1.46.1 (released March 12th). It
went in March 23rd and will be in the next release. Until then... I guess
one option is to use the release branch from the SVN:

https://svn.boost.org/svn/boost/branches/release

or to copy only the following files from it:

boost/smart_ptr/
    detail/shared_count.hpp
    detail/sp_counted_impl.hpp
    make_shared.hpp

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [shared_ptr] make_shared causes Access Violation

Paul Heil
Yes, that fixes the issue. Thanks!

Is there an expected release date for the next update?

-PaulH

On Wed, May 11, 2011 at 9:08 AM, Peter Dimov <[hidden email]> wrote:
Paul Heil wrote:

The callstack is the same with boost 1.46.1.

Yes, you're right, sorry. The fix is not in 1.46.1 (released March 12th). It went in March 23rd and will be in the next release. Until then... I guess one option is to use the release branch from the SVN:

https://svn.boost.org/svn/boost/branches/release

or to copy only the following files from it:

boost/smart_ptr/
  detail/shared_count.hpp
  detail/sp_counted_impl.hpp
  make_shared.hpp


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Loading...