Bug 1055852 - Plug bunches of leaks that signaling_unittest hits, mostly in sipcc. r=mccr8

This commit is contained in:
Byron Campen [:bwc] 2014-08-21 15:11:19 -07:00
parent 0edfb51260
commit 947c2f60c4
16 changed files with 110 additions and 45 deletions

View File

@ -1275,8 +1275,17 @@ int vcmRxStartICE(cc_mcapid_t mcap_id,
configs.push_back(config_raw);
}
if (conduit->ConfigureRecvMediaCodecs(configs))
auto error = conduit->ConfigureRecvMediaCodecs(configs);
// Would be nice to use a smart container, but we'd need to change
// a lot of code.
for (auto it = configs.begin(); it != configs.end(); ++it) {
delete *it;
}
if (error) {
return VCM_ERROR;
}
// Now we have all the pieces, create the pipeline
mozilla::RefPtr<mozilla::MediaPipelineReceiveAudio> pipeline =
@ -1330,13 +1339,23 @@ int vcmRxStartICE(cc_mcapid_t mcap_id,
ccsdpCodecName(payloads[i].codec_type),
payloads[i].video.rtcp_fb_types);
if (vcmEnsureExternalCodec(conduit, config_raw, false)) {
delete config_raw;
continue;
}
configs.push_back(config_raw);
}
if (conduit->ConfigureRecvMediaCodecs(configs))
auto error = conduit->ConfigureRecvMediaCodecs(configs);
// Would be nice to use a smart container, but we'd need to change
// a lot of code.
for (auto it = configs.begin(); it != configs.end(); ++it) {
delete *it;
}
if (error) {
return VCM_ERROR;
}
// Now we have all the pieces, create the pipeline
mozilla::RefPtr<mozilla::MediaPipelineReceiveVideo> pipeline =

View File

@ -1323,7 +1323,7 @@ static void AddTrackAndListener(MediaStream* source,
// to the "start" time for the track
segment_->AppendNullData(current_ticks);
mStream->AsSourceStream()->AddTrack(track_id_, track_rate_,
current_ticks, segment_);
current_ticks, segment_.forget());
// AdvanceKnownTracksTicksTime(HEAT_DEATH_OF_UNIVERSE) means that in
// theory per the API, we can't add more tracks before that
// time. However, the impl actually allows it, and it avoids a whole
@ -1338,7 +1338,7 @@ static void AddTrackAndListener(MediaStream* source,
private:
TrackID track_id_;
TrackRate track_rate_;
MediaSegment* segment_;
nsAutoPtr<MediaSegment> segment_;
nsRefPtr<MediaStreamListener> listener_;
const RefPtr<TrackAddedCallback> completed_;
};

View File

@ -255,6 +255,7 @@ public:
streams = aInfo->getMediaStreams();
mRemoteStream = mPC->media()->GetRemoteStream(streams->media_stream_id);
MOZ_ASSERT(mRemoteStream);
cpr_free(streams);
} else if (mCallState == FOUNDICECANDIDATE) {
mCandidateStr = aInfo->getCandidate();
} else if ((mCallState == CREATEOFFERSUCCESS) ||

View File

@ -140,6 +140,7 @@ public:
return false;
}
addStunServer(*server);
delete server;
return true;
}
bool addTurnServer(const std::string& addr, uint16_t port,
@ -157,6 +158,7 @@ public:
return false;
}
addTurnServer(*server);
delete server;
return true;
}
void addStunServer(const NrIceStunServer& server) { mStunServers.push_back (server); }

View File

@ -148,37 +148,34 @@ DEB_F_PREFIX_ARGS(SIP_CC_PROV, "CCAPI_ApplyTranslationMask"));
* Before initing the line_info release any memory which has been used
* so we do not leak any here.
*/
void ccsnap_line_pre_init () {
void ccsnap_line_free () {
int i;
CCAPP_DEBUG(DEB_F_PREFIX"Entering line_pre_init to clear it out to avoid mem leaks", DEB_F_PREFIX_ARGS(SIP_CC_PROV, "ccsnap_line_pre_init"));
CCAPP_DEBUG(DEB_F_PREFIX"Entering", DEB_F_PREFIX_ARGS(SIP_CC_PROV, __FUNCTION__));
for (i=1;i<MAX_CONFIG_LINES;i++) {
if ((lineInfo[i].name) && (strlen(lineInfo[i].name) > 0)) {
for (i=1;i<=MAX_CONFIG_LINES;i++) {
if (lineInfo[i].name) {
strlib_free(lineInfo[i].name);
}
if ((lineInfo[i].dn) && (strlen(lineInfo[i].dn) > 0)) {
if (lineInfo[i].dn) {
strlib_free(lineInfo[i].dn);
}
if ((lineInfo[i].cfwd_dest) && (strlen(lineInfo[i].cfwd_dest) > 0)) {
if (lineInfo[i].cfwd_dest) {
strlib_free(lineInfo[i].cfwd_dest);
}
if ((lineInfo[i].externalNumber) &&
(strlen(lineInfo[i].externalNumber) > 0)) {
if (lineInfo[i].externalNumber) {
strlib_free(lineInfo[i].externalNumber);
}
if ((featureInfo[i].speedDialNumber) &&
(strlen(featureInfo[i].speedDialNumber) > 0)) {
if (featureInfo[i].speedDialNumber) {
strlib_free(featureInfo[i].speedDialNumber);
}
if ((featureInfo[i].contact) && (strlen(featureInfo[i].contact) > 0)) {
if (featureInfo[i].contact) {
strlib_free(featureInfo[i].contact);
}
if ((featureInfo[i].name) && (strlen(featureInfo[i].name) > 0)) {
if (featureInfo[i].name) {
strlib_free(featureInfo[i].name);
}
if ((featureInfo[i].retrievalPrefix) &&
(strlen(featureInfo[i].retrievalPrefix) > 0)) {
if (featureInfo[i].retrievalPrefix) {
strlib_free(featureInfo[i].retrievalPrefix);
}
}
@ -194,7 +191,7 @@ void ccsnap_line_init() {
char maskStr[MAX_EXTERNAL_NUMBER_MASK_SIZE];
/* clean up structure if need be */
ccsnap_line_pre_init();
ccsnap_line_free();
memset(lineInfo, 0, MAX_CONFIG_LINES*sizeof(cc_line_info_t));
memset(featureInfo, 0, MAX_CONFIG_LINES*sizeof(cc_feature_info_t));
@ -322,18 +319,17 @@ cc_feature_info_t* ccsnap_getFeatureInfo(int featureIndex)
/**
* Release any used mem to avoid a leak.
*/
void ccsnap_device_pre_init () {
void ccsnap_device_free () {
int i = 0;
CCAPP_DEBUG(DEB_F_PREFIX"Entering device_pre_init to clear it out to avoid mem leaks", DEB_F_PREFIX_ARGS(SIP_CC_PROV, "ccsnap_device_pre_init"));
if ((g_deviceInfo.not_prompt) && (strlen(g_deviceInfo.not_prompt) > 0)) {
CCAPP_DEBUG(DEB_F_PREFIX"Entering", DEB_F_PREFIX_ARGS(SIP_CC_PROV, __FUNCTION__));
if (g_deviceInfo.not_prompt) {
strlib_free(g_deviceInfo.not_prompt);
}
i = 0;
while (i < CCAPI_MAX_SERVERS) {
if ((g_deviceInfo.ucm[i].name) &&
(strlen(g_deviceInfo.ucm[i].name) > 0)) {
if (g_deviceInfo.ucm[i].name) {
strlib_free(g_deviceInfo.ucm[i].name);
}
i++;
@ -344,7 +340,7 @@ void ccsnap_device_init() {
char temp[MAX_SIP_URL_LENGTH];
/* clean up structure if need be */
ccsnap_device_pre_init();
ccsnap_device_free();
memset (&g_deviceInfo, 0, sizeof(g_deviceInfo));
g_deviceInfo.not_prompt =strlib_empty();

View File

@ -92,7 +92,9 @@ extern cc_line_info_t lineInfo[MAX_CONFIG_LINES+1];
cc_line_info_t* ccsnap_getLineInfo(int lineID);
cc_line_info_t* ccsnap_getLineInfoFromBtn(int btnID);
void ccsnap_line_init();
void ccsnap_line_free();
void ccsnap_device_init();
void ccsnap_device_free();
void ccsnap_gen_deviceEvent(ccapi_device_event_e event, cc_device_handle_t handle);
void ccsnap_gen_lineEvent(ccapi_line_event_e event, cc_lineid_t handle);
void ccsnap_gen_callEvent(ccapi_call_event_e event, cc_call_handle_t handle);

View File

@ -1019,6 +1019,8 @@ void CCApp_processCmds(unsigned int cmd, unsigned int reason, string_t reasonStr
case CMD_UNREGISTER_ALL_LINES:
/* send a shutdown message to the SIP Task */
SIPTaskPostShutdown(SIP_EXTERNAL, reason, reasonStr);
ccsnap_line_free();
ccsnap_device_free();
break;
case CMD_RESTART:
SIPTaskPostRestart(TRUE);
@ -1505,6 +1507,7 @@ static void ccappUpdateSessionData (session_update_t *sessUpd)
state_data.media_stream_track_id;
data->media_stream_id = sessUpd->update.ccSessionUpd.data.
state_data.media_stream_id;
strlib_free(data->status);
data->status =
sessUpd->update.ccSessionUpd.data.state_data.reason_text;
break;
@ -1761,6 +1764,7 @@ static void ccappUpdateSessionData (session_update_t *sessUpd)
data->status = ccsnap_EscapeStrToLocaleStr(data->status, sessUpd->update.ccSessionUpd.data.status.status, LEN_UNKNOWN);
if (data->status != NULL) {
if(strncmp(data->status, UNKNOWN_PHRASE_STR, UNKNOWN_PHRASE_STR_SIZE) == 0){
strlib_free(data->status);
data->status = strlib_empty();
}
if(strcmp(data->status, strlib_empty()) != 0){
@ -1847,9 +1851,11 @@ static void ccappUpdateSessionData (session_update_t *sessUpd)
case ICE_CANDIDATE_FOUND:
if (sessUpd->update.ccSessionUpd.data.state_data.extra) {
if (sessUpd->eventID == ICE_CANDIDATE_FOUND) {
strlib_free(data->candidate);
data->candidate = sessUpd->update.ccSessionUpd.data.state_data.extra;
}
}
strlib_free(data->sdp);
data->sdp = sessUpd->update.ccSessionUpd.data.state_data.sdp;
/* Fall through to the next case... */
case REMOTE_STREAM_ADD:

View File

@ -404,6 +404,10 @@ send_task_unload_msg(cc_srcs_t dest_id)
}
CSFLogError("common", "%s: send UNLOAD msg to CCapp thread good",
fname);
/* Unlike other similar functions, ccappTaskPostMsg does not take
* ownership. */
cpr_free(msg);
msg = NULL;
}
break;

View File

@ -1216,9 +1216,10 @@ static void send_message_helper(
(msg_id == CC_MSG_CREATEANSWER ||
msg_id == CC_MSG_SETLOCALDESC ||
msg_id == CC_MSG_SETREMOTEDESC)) {
size_t sdp_size = strlen(sdp) + 1;
pmsg->sdp = cpr_malloc(sdp_size);
sstrncpy(pmsg->sdp, sdp, sdp_size);
/* This is safe because all of the queueing has been removed.
* From a few minutes of looking, it appears to be very messy to
* clean this up down in the implementation. */
pmsg->sdp = sdp;
} else {
pmsg->sdp = NULL;
}

View File

@ -4051,7 +4051,7 @@ fsmdef_ev_addcandidate(sm_event_t *event) {
dcb->caller_id.call_instance_id, strlib_malloc(remote_sdp,-1),
msg->timecard, PC_NO_ERROR, NULL);
free(remote_sdp);
cpr_free(remote_sdp);
return (SM_RC_END);
}
@ -4130,6 +4130,7 @@ fsmdef_ev_foundcandidate(sm_event_t *event) {
strlib_malloc(candidate_tmp, -1),
msg->timecard, PC_NO_ERROR, NULL);
cpr_free(local_sdp);
return SM_RC_END;
}
@ -9009,6 +9010,7 @@ fsmdef_shutdown (void)
FSM_FOR_ALL_CBS(dcb, fsmdef_dcbs, FSMDEF_MAX_DCBS) {
/* clean media list */
gsmsdp_clean_media_list(dcb);
gsmsdp_free(dcb);
}
/* destroy free media structure list */

View File

@ -449,6 +449,13 @@ gsmsdp_free_media (fsmdef_media_t *media)
media->payloads = NULL;
media->num_payloads = 0;
}
if (media->previous_sdp.payloads != NULL) {
cpr_free(media->previous_sdp.payloads);
media->previous_sdp.payloads = NULL;
media->previous_sdp.num_payloads = 0;
}
/*
* Check to see if the element is part of the
* free chunk space.
@ -7364,9 +7371,26 @@ gsmsdp_configure_dtls_data_attributes(fsm_fcb_t *fcb_p)
void
gsmsdp_free (fsmdef_dcb_t *dcb_p)
{
if ((dcb_p != NULL) && (dcb_p->sdp != NULL)) {
sipsdp_free(&dcb_p->sdp);
dcb_p->sdp = NULL;
if (dcb_p != NULL) {
if (dcb_p->sdp != NULL) {
sipsdp_free(&dcb_p->sdp);
dcb_p->sdp = NULL;
}
if (dcb_p->media_cap_tbl) {
cpr_free(dcb_p->media_cap_tbl);
dcb_p->media_cap_tbl = NULL;
}
if (dcb_p->remote_media_stream_tbl) {
cpr_free(dcb_p->remote_media_stream_tbl);
dcb_p->remote_media_stream_tbl = NULL;
}
if (dcb_p->local_media_track_tbl) {
cpr_free(dcb_p->local_media_track_tbl);
dcb_p->local_media_track_tbl = NULL;
}
}
}

View File

@ -647,6 +647,7 @@ lsm_open_rx (lsm_lcb_t *lcb, cc_action_data_open_rcv_t *data,
if (!status) {
sstrncpy(dcb->ice_default_candidate_addr, default_addr, sizeof(dcb->ice_default_candidate_addr));
cpr_free(default_addr);
data->port = (uint16_t)port_allocated;
media->candidate_ct = candidate_ct;

View File

@ -335,6 +335,7 @@ sipsdp_write_to_buf (sdp_t *sdp_info, uint32_t *retbytes)
if (!sdp_info) {
CCSIP_DEBUG_ERROR(SIP_F_PREFIX"NULL sdp_info or src_sdp", __FUNCTION__);
flex_string_free(&fs);
return (NULL);
}

View File

@ -132,7 +132,9 @@ class Fake_SourceMediaStream : public Fake_MediaStream {
mPeriodic(new Fake_MediaPeriodic(this)) {}
void AddTrack(mozilla::TrackID aID, mozilla::TrackRate aRate, mozilla::TrackTicks aStart,
mozilla::MediaSegment* aSegment) {}
mozilla::MediaSegment* aSegment) {
delete aSegment;
}
void EndTrack(mozilla::TrackID aID) {}
bool AppendToTrack(mozilla::TrackID aID, mozilla::MediaSegment* aSegment,

View File

@ -61,7 +61,7 @@ public:
std::vector<mozilla::DOMMediaStream *> GetStreams() { return streams; }
ResponseState state;
char *lastString;
std::string lastString;
sipcc::PeerConnectionImpl::Error lastStatusCode;
mozilla::dom::PCObserverStateType lastStateType;
int addIceSuccessCount;

View File

@ -285,7 +285,7 @@ NS_IMPL_ISUPPORTS(TestObserver, nsISupportsWeakReference)
NS_IMETHODIMP
TestObserver::OnCreateOfferSuccess(const char* offer, ER&)
{
lastString = strdup(offer);
lastString = offer;
state = stateSuccess;
std::cout << name << ": onCreateOfferSuccess = " << std::endl << indent(offer)
<< std::endl;
@ -305,7 +305,7 @@ TestObserver::OnCreateOfferError(uint32_t code, const char *message, ER&)
NS_IMETHODIMP
TestObserver::OnCreateAnswerSuccess(const char* answer, ER&)
{
lastString = strdup(answer);
lastString = answer;
state = stateSuccess;
std::cout << name << ": onCreateAnswerSuccess =" << std::endl
<< indent(answer) << std::endl;
@ -1048,8 +1048,8 @@ class SignalingAgent {
return pObserver->MatchingCandidates(cand);
}
char* offer() const { return offer_; }
char* answer() const { return answer_; }
const char* offer() const { return offer_.c_str(); }
const char* answer() const { return answer_.c_str(); }
std::string getLocalDescription() const {
char *sdp = nullptr;
@ -1057,7 +1057,9 @@ class SignalingAgent {
if (!sdp) {
return "";
}
return sdp;
std::string result(sdp);
delete sdp;
return result;
}
std::string getRemoteDescription() const {
@ -1066,7 +1068,9 @@ class SignalingAgent {
if (!sdp) {
return "";
}
return sdp;
std::string result(sdp);
delete sdp;
return result;
}
// Adds a stream to the PeerConnection.
@ -1128,7 +1132,7 @@ class SignalingAgent {
ASSERT_TRUE_WAIT(pObserver->state != TestObserver::stateNoResponse,
kDefaultTimeout);
ASSERT_EQ(pObserver->state, TestObserver::stateSuccess);
SDPSanityCheck(pObserver->lastString, sdpCheck, true);
SDPSanityCheck(pObserver->lastString.c_str(), sdpCheck, true);
ASSERT_EQ(signaling_state(), endState);
offer_ = pObserver->lastString;
}
@ -1156,7 +1160,7 @@ void CreateAnswer(uint32_t offerAnswerFlags,
ASSERT_TRUE_WAIT(pObserver->state != TestObserver::stateNoResponse,
kDefaultTimeout);
ASSERT_EQ(pObserver->state, TestObserver::stateSuccess);
SDPSanityCheck(pObserver->lastString, sdpCheck, false);
SDPSanityCheck(pObserver->lastString.c_str(), sdpCheck, false);
ASSERT_EQ(signaling_state(), endState);
answer_ = pObserver->lastString;
@ -1184,7 +1188,7 @@ void CreateAnswer(uint32_t offerAnswerFlags,
ASSERT_TRUE_WAIT(pObserver->state != TestObserver::stateNoResponse,
kDefaultTimeout);
ASSERT_TRUE(pObserver->state == TestObserver::stateSuccess);
SDPSanityCheck(pObserver->lastString, sdpCheck, true);
SDPSanityCheck(pObserver->lastString.c_str(), sdpCheck, true);
offer_ = pObserver->lastString;
}
@ -1425,8 +1429,8 @@ void CreateAnswer(uint32_t offerAnswerFlags,
public:
nsRefPtr<PCDispatchWrapper> pc;
nsRefPtr<TestObserver> pObserver;
char* offer_;
char* answer_;
std::string offer_;
std::string answer_;
nsRefPtr<DOMMediaStream> domMediaStream_;
sipcc::IceConfiguration cfg_;
const std::string name;