Skip to content

Commit

Permalink
Fix crashes when getting local sdp (#1447)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun committed Aug 8, 2019
1 parent fa5ff61 commit 5af7246
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions erizo/src/erizo/WebRtcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ boost::future<std::shared_ptr<SdpInfo>> WebRtcConnection::getLocalSdpInfo() {
if (auto this_ptr = weak_this.lock()) {
info = this_ptr->getLocalSdpInfoSync();
} else {
ELOG_WARN("%s message: Error trying to getLocalSdpInfo, returning empty", this_ptr->toLog());
ELOG_WARN("message: Error trying to getLocalSdpInfo - cannot lock WebrtcConnection, returning empty");
}
task_promise->set_value(info);
});
Expand Down Expand Up @@ -331,7 +331,8 @@ std::shared_ptr<SdpInfo> WebRtcConnection::getLocalSdpInfoSync() {
local_sdp_->videoDirection = erizo::SENDRECV;
}

return local_sdp_;
auto local_sdp_copy = std::make_shared<SdpInfo>(*local_sdp_.get());
return local_sdp_copy;
}

boost::future<void> WebRtcConnection::setRemoteSdp(const std::string &sdp) {
Expand Down
11 changes: 8 additions & 3 deletions erizoAPI/WebRtcConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,14 @@ NAN_METHOD(WebRtcConnection::getLocalDescription) {

me->getLocalSdpInfo().then(
[persistent, obj] (boost::future<std::shared_ptr<erizo::SdpInfo>> fut) {
std::shared_ptr<erizo::SdpInfo> sdp_info = std::make_shared<erizo::SdpInfo>(*fut.get().get());
ResultVariant result = sdp_info;
obj->notifyFuture(persistent, result);
std::shared_ptr<erizo::SdpInfo> sdp_info = fut.get();
if (sdp_info) {
std::shared_ptr<erizo::SdpInfo> sdp_info_copy = std::make_shared<erizo::SdpInfo>(*sdp_info.get());
ResultVariant result = sdp_info_copy;
obj->notifyFuture(persistent, result);
} else {
obj->notifyFuture(persistent);
}
});
info.GetReturnValue().Set(resolver->GetPromise());
}
Expand Down
8 changes: 8 additions & 0 deletions erizo_controller/erizoJS/models/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class Connection extends events.EventEmitter {

getLocalSdp() {
return this.wrtc.getLocalDescription().then((desc) => {
if (!desc) {
log.error('Cannot get local description');
return '';
}
this.wrtc.localDescription = new SessionDescription(desc);
const sdp = this.wrtc.localDescription.getSdp(this.sessionVersion);
this.sessionVersion += 1;
Expand Down Expand Up @@ -180,6 +184,10 @@ class Connection extends events.EventEmitter {
return Promise.reject('fail');
}
return this.wrtc.getLocalDescription().then((localDescription) => {
if (!localDescription) {
log.error('message: _resendLastAnswer, Cannot get local description');
return Promise.reject('fail');
}
this.wrtc.localDescription = new SessionDescription(localDescription);
const sdp = this.wrtc.localDescription.getSdp(this.sessionVersion);
const stream = sdp.getStream(label);
Expand Down

0 comments on commit 5af7246

Please sign in to comment.