cutelyst / simple-mail

An SMTP library written in C++ for Qt. Allows applications to send emails (MIME with text, html, attachments, inline files, etc.) via SMTP. Supports SSL and SMTP authentication.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blocking code crashes after code block finishes

joshorenberg opened this issue · comments

I am running Qt Created based on Qt 5.15.2. The blocking code crashes after the code block completes. The email sends successfully. I borrowed code from the example and modified it. Application output is Critical error detected c0000374. Here is the backtrace:

backtrace cl

Thanks!

no clue without seeing actual code, or a minimal code that crashes

Here 'tis, a little stripped for the relevant parts only. The situation I've been testing is with a multimap with only one key value pair and the program crashes when exiting the inner code block. Thanks!

void Program::sendEmails()
{
    QMultiMap<QString,BackupJob>::const_iterator iterator = emailAddressMultiMap.constBegin();
    while (iterator != emailAddressMultiMap.constEnd())
    {
        messageString += ... //construct the string here

        SimpleMail::Sender sender("smtp.***.com", 465, SimpleMail::Sender::SslConnection);

        sender.setUser("address@***.com");
        sender.setPassword("password");

        SimpleMail::MimeMessage message;
        message.setSender(SimpleMail::EmailAddress("from@from.com", "Program"));
        message.addTo(SimpleMail::EmailAddress(iterator.key()));
        message.setSubject("Email");

        SimpleMail::MimeText text;
        text.setText(messageString);
        message.addPart(&text);

        sender.sendMail(message); // Blocks untill mail is delivered or errored
        //qDebug() << sender.responseText();
        sender.quit();

        QString emailAddress = iterator.key();
        while (iterator != emailAddressMultiMap.constEnd() && iterator.key() == emailAddress)
            ++iterator;
    }
}

addPart() takes ownership of part so it will crash as it get's deleted twice.

How to remedy? Also that code was borrowed from example 1 and the main page example, would be nice to update for the newbies out there (and maybe not so newbies...) Or is it a bug? Thanks for the quick response.

Still getting a crash exiting the code block, new backtrace:

backtrace cl2

I found a workaround for the error... I offloaded the email sending code to a worker thread (which is what I wanted in the first place) and everything is working now, no more crashes. Weird...