Hi,
I have a class with a string variable like

Code:
#ifdef __GNUC__
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#elif DLL_PUBLIC_IMPORT
#define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
#else
#define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
#endif

class Status
    {
    public:
        enum Errors
        {
            SUCCESS,
            FAILURE,
         };
        
        std::string msg;
}

DLL_PUBLIC  Status fun()
{
Status obj;
return obj;
}
No when i call the function fun in a client problem then it is crashing.

Code:
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffffe880921 in __GI_abort () at abort.c:79
#2  0x00007ffffe8c9967 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffffe9f6b0d "%s\n") at ../sysdeps/posix/libc_fatal.c:181
#3  0x00007ffffe8d09da in malloc_printerr (str=str@entry=0x7ffffe9f8720 "munmap_chunk(): invalid pointer") at malloc.c:5342
#4  0x00007ffffe8d7fbc in munmap_chunk (p=0x7fffff7d1938) at malloc.c:2846
#5  __GI___libc_free (mem=0x7fffff7d1948) at malloc.c:3127
#6  0x00000000080062dc in __gnu_cxx::new_allocator<char>::deallocate(char*, unsigned long) ()
#7  0x0000000008005e61 in std::allocator_traits<std::allocator<char> >::deallocate(std::allocator<char>&, char*, unsigned long) ()
#8  0x000000000800590c in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_destroy(unsigned long) ()
#9  0x0000000008005734 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose() ()
#10 0x00000000080052c4 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() ()
#11 0x0000000008004b94 in Status::~Status() ()
#12 0x000000000800480d in main ()
so free is getting called for the string object and it is crashing. Any suggestion how to avoid this
requirements
1) i need to return the object not the pointer
2) i need the string object in the class i.e std::string msg