Commit 261b0f19 authored by jehan's avatar jehan

fix crash when destroying LinphoneCore during file upload

parent 61c79b43
......@@ -152,6 +152,9 @@ public:
void updateInDb ();
private:
ChatMessagePrivate(const std::shared_ptr<AbstractChatRoom> &cr, ChatMessage::Direction dir);
static bool validStateTransition (ChatMessage::State currentState, ChatMessage::State newState);
// TODO: Clean attributes.
......@@ -198,7 +201,6 @@ private:
bool encryptionPrevented = false;
bool toBeStored = true;
mutable bool contentsNotLoadedFromDatabase = false;
L_DECLARE_PUBLIC(ChatMessage);
};
......
......@@ -52,6 +52,11 @@ using namespace B64_NAMESPACE;
LINPHONE_BEGIN_NAMESPACE
ChatMessagePrivate::ChatMessagePrivate(const std::shared_ptr<AbstractChatRoom> &cr, ChatMessage::Direction dir):fileTransferChatMessageModifier(cr->getCore()->getCCore()->http_provider) {
direction = dir;
setChatRoom(cr);
}
void ChatMessagePrivate::setDirection (ChatMessage::Direction dir) {
direction = dir;
}
......@@ -829,15 +834,12 @@ bool ChatMessagePrivate::validStateTransition (ChatMessage::State currentState,
// -----------------------------------------------------------------------------
ChatMessage::ChatMessage (const shared_ptr<AbstractChatRoom> &chatRoom, ChatMessage::Direction direction) :
Object(*new ChatMessagePrivate), CoreAccessor(chatRoom->getCore()) {
L_D();
d->direction = direction;
d->setChatRoom(chatRoom);
Object(*new ChatMessagePrivate(chatRoom,direction)), CoreAccessor(chatRoom->getCore()) {
}
ChatMessage::~ChatMessage () {
L_D();
for (Content *content : d->contents)
delete content;
......
......@@ -35,7 +35,7 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
FileTransferChatMessageModifier::FileTransferChatMessageModifier () {
FileTransferChatMessageModifier::FileTransferChatMessageModifier (belle_http_provider_t *prov) : provider(prov) {
bgTask.setName("File transfer upload");
}
......@@ -48,7 +48,10 @@ void FileTransferChatMessageModifier::setHttpRequest (belle_http_request_t *requ
}
FileTransferChatMessageModifier::~FileTransferChatMessageModifier () {
releaseHttpRequest();
if (isFileTransferInProgressAndValid())
cancelFileTransfer(); //to avoid body handler to still refference zombie FileTransferChatMessageModifier
else
releaseHttpRequest();
}
ChatMessageModifier::Result FileTransferChatMessageModifier::encode (const shared_ptr<ChatMessage> &message, int &errorCode) {
......@@ -474,7 +477,7 @@ int FileTransferChatMessageModifier::startHttpTransfer (const string &url, const
// give msg to listener to be able to start the actual file upload when server answer a 204 No content
httpListener = belle_http_request_listener_create_from_callbacks(cbs, this);
belle_http_provider_send_request(message->getCore()->getCCore()->http_provider, httpRequest, httpListener);
belle_http_provider_send_request(provider, httpRequest, httpListener);
return 0;
error:
......@@ -941,10 +944,11 @@ void FileTransferChatMessageModifier::cancelFileTransfer () {
? L_C_TO_STRING(linphone_core_get_file_transfer_server(message->getCore()->getCCore()))
: currentFileContentToTransfer->getFilePath().c_str()
);
belle_http_provider_cancel_request(message->getCore()->getCCore()->http_provider, httpRequest);
} else {
lInfo() << "Warning: http request still running for ORPHAN msg: this is a memory leak";
}
belle_http_provider_cancel_request(provider, httpRequest);
}
releaseHttpRequest();
}
......
......@@ -36,7 +36,7 @@ class FileTransferContent;
class FileTransferChatMessageModifier : public ChatMessageModifier {
public:
FileTransferChatMessageModifier ();
FileTransferChatMessageModifier (belle_http_provider_t *prov);
~FileTransferChatMessageModifier ();
Result encode (const std::shared_ptr<ChatMessage> &message, int &errorCode) override;
......@@ -77,6 +77,7 @@ private:
belle_http_request_t *httpRequest = nullptr;
belle_http_request_listener_t *httpListener = nullptr;
belle_http_provider_t *provider = nullptr;
BackgroundTask bgTask;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment