simple-mail
simple-mail copied to clipboard
Program crashes when destructing "SimpleMail::MimeMessage" after calling "SimpleMail::MimeMessage::addPart"
I have the following 3 lines in a function:
SimpleMail::MimeText text;
SimpleMail::MimeMessage message;
message.addPart(&text);
When the function exists, the program crashes as soon as it gets to the destruction of SimpleMail::MimeText.
If I remove the line message.addPart(&text);, it works "fine".
I tried using the (blocking) code from the readme, and the demos. But both have the same problem.
This is the error I'm getting:
*** Error in `[Project path]': double free or corruption (out): 0x00007fffb0eff300 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777f5)[0x7f57002117f5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8038a)[0x7f570021a38a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f570021e58c]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(_ZN10SimpleMail8MimeTextD0Ev+0x24)[0x7f570126d47c]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(+0x13f19)[0x7f5701269f19]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(+0x13bf8)[0x7f5701269bf8]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(+0x13554)[0x7f5701269554]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(+0x135a0)[0x7f57012695a0]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(+0x15f4b)[0x7f570126bf4b]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(_ZN10SimpleMail8MimePartD1Ev+0x2e)[0x7f570126a3c2]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(_ZN10SimpleMail13MimeMultiPartD1Ev+0x2a)[0x7f57012691b8]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(_ZN10SimpleMail13MimeMultiPartD0Ev+0x18)[0x7f57012691e8]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(+0xeaac)[0x7f5701264aac]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(+0x102af)[0x7f57012662af]
/usr/lib/x86_64-linux-gnu/libSimpleMail2Qt5.so.0(_ZN10SimpleMail11MimeMessageD1Ev+0x2e)[0x7f5701263516]
[Project path][0x4040dc]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f57001ba840]
[Project path][0x402399]
...
(There's a section about Memory maps, it's very long, so I'm not sure if I should include it yet)
I'm using QT 5.11.1, Ubuntu 16.04, and GCC 5.4.0
addPart() expects an object allocated on the heap not stack, it will take ownership
In the examples, and demos you have that exact code, is that intentional? Also, it seems kinda wasteful to allocate the heap. Is there a way to disable "ownership"?
if you look at the async examples it's on the heap https://github.com/cutelyst/simple-mail/blob/a7fd7f756ce8d2081607299f09c908f1e39e762a/README.md?plain=1#L53 How else can it live to be processed later when doing it async?
Why would SimpleMail::MimeMessage take ownership of SimpleMail::MimeText when working in non async context?
Your blocking examples show the "exact" code I have.
https://github.com/cutelyst/simple-mail/blob/a7fd7f756ce8d2081607299f09c908f1e39e762a/README.md?plain=1#L94-L106
How else can it live to be processed later when doing it async?
Can't argue with that, in an async context.
But I'm using blocking code, I don't need async. I think the fix is very simple, just add something like an isAsync flag or something
Why would SimpleMail::MimeMessage take ownership of SimpleMail::MimeText when working in non async context?
Because it's nearly the same API and was created like this in the past, I also don't care much about the blocking one right now.
V3 API now uses std::shared_ptr, usage should be clearer