summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Antonov <vlantonov@luxoft.com>2016-07-08 18:00:39 +0300
committerVladislav Antonov <vlantonov@luxoft.com>2016-07-12 17:18:08 +0300
commit769b3c6bbc4880e690a1458c0d0ba9b4c349269b (patch)
treecae56ab3bfb52b3abe2aac69f3270dd2a12c4c78
parenteb9091afef3b9bce637248ecc35ffabd0a846567 (diff)
downloadsdl_core-769b3c6bbc4880e690a1458c0d0ba9b4c349269b.tar.gz
Fix invalid memory access.
Fixed access to deleted fields in Timer and StreamerAdapter. Fixed uninitialized values in request_controller. Related Issue: APPLINK-25098
-rw-r--r--src/components/application_manager/include/application_manager/request_info.h4
-rw-r--r--src/components/application_manager/src/request_controller.cc8
-rw-r--r--src/components/media_manager/src/streamer_adapter.cc2
-rw-r--r--src/components/policy/src/sql_pt_representation.cc1
-rw-r--r--src/components/utils/include/utils/timer.h3
-rw-r--r--src/components/utils/src/timer.cc25
6 files changed, 23 insertions, 20 deletions
diff --git a/src/components/application_manager/include/application_manager/request_info.h b/src/components/application_manager/include/application_manager/request_info.h
index b6b754ba5c..193699be78 100644
--- a/src/components/application_manager/include/application_manager/request_info.h
+++ b/src/components/application_manager/include/application_manager/request_info.h
@@ -63,7 +63,9 @@ struct RequestInfo {
RequestInfo(RequestPtr request,
const RequestType requst_type,
const uint64_t timeout_msec)
- : request_(request), timeout_msec_(timeout_msec) {
+ : request_(request)
+ , timeout_msec_(timeout_msec)
+ , hmi_level_(mobile_apis::HMILevel::INVALID_ENUM) {
start_time_ = date_time::DateTime::getCurrentTime();
updateEndTime();
requst_type_ = requst_type;
diff --git a/src/components/application_manager/src/request_controller.cc b/src/components/application_manager/src/request_controller.cc
index 9a2927ea27..b2ced9b01b 100644
--- a/src/components/application_manager/src/request_controller.cc
+++ b/src/components/application_manager/src/request_controller.cc
@@ -190,8 +190,8 @@ RequestController::TResult RequestController::addHMIRequest(
const uint64_t timeout_in_mseconds =
static_cast<uint64_t>(request->default_timeout());
- RequestInfoPtr request_info_ptr(
- new HMIRequestInfo(request, timeout_in_mseconds));
+ RequestInfoPtr request_info_ptr =
+ utils::MakeShared<HMIRequestInfo>(request, timeout_in_mseconds);
if (0 == timeout_in_mseconds) {
LOG4CXX_DEBUG(logger_,
@@ -446,8 +446,8 @@ void RequestController::Worker::threadMain() {
// default timeout
const uint32_t timeout_in_mseconds = request_ptr->default_timeout();
- RequestInfoPtr request_info_ptr(
- new MobileRequestInfo(request_ptr, timeout_in_mseconds));
+ RequestInfoPtr request_info_ptr =
+ utils::MakeShared<MobileRequestInfo>(request_ptr, timeout_in_mseconds);
request_controller_->waiting_for_response_.Add(request_info_ptr);
LOG4CXX_DEBUG(logger_, "timeout_in_mseconds " << timeout_in_mseconds);
diff --git a/src/components/media_manager/src/streamer_adapter.cc b/src/components/media_manager/src/streamer_adapter.cc
index 44f46d92b2..20c067da1c 100644
--- a/src/components/media_manager/src/streamer_adapter.cc
+++ b/src/components/media_manager/src/streamer_adapter.cc
@@ -44,9 +44,9 @@ StreamerAdapter::StreamerAdapter(Streamer* const streamer)
}
StreamerAdapter::~StreamerAdapter() {
+ delete streamer_;
thread_->join();
threads::DeleteThread(thread_);
- delete streamer_;
}
void StreamerAdapter::StartActivity(int32_t application_key) {
diff --git a/src/components/policy/src/sql_pt_representation.cc b/src/components/policy/src/sql_pt_representation.cc
index b94e9306d3..657f60eb38 100644
--- a/src/components/policy/src/sql_pt_representation.cc
+++ b/src/components/policy/src/sql_pt_representation.cc
@@ -644,7 +644,6 @@ bool SQLPTRepresentation::GatherConsumerFriendlyMessages(
if (query.Prepare(sql_pt::kCollectFriendlyMsg)) {
while (query.Next()) {
-
UserFriendlyMessage msg;
msg.message_code = query.GetString(7);
std::string language = query.GetString(6);
diff --git a/src/components/utils/include/utils/timer.h b/src/components/utils/include/utils/timer.h
index 42d5df22a5..690c9df5dc 100644
--- a/src/components/utils/include/utils/timer.h
+++ b/src/components/utils/include/utils/timer.h
@@ -34,6 +34,7 @@
#include <string>
#include <stdint.h>
+#include <memory>
#include "utils/macro.h"
#include "utils/lock.h"
@@ -200,7 +201,7 @@ class Timer {
mutable sync_primitives::Lock state_lock_;
- mutable TimerDelegate delegate_;
+ mutable std::auto_ptr<TimerDelegate> delegate_;
threads::Thread* thread_;
/**
diff --git a/src/components/utils/src/timer.cc b/src/components/utils/src/timer.cc
index a91151354e..00272a73eb 100644
--- a/src/components/utils/src/timer.cc
+++ b/src/components/utils/src/timer.cc
@@ -47,8 +47,8 @@ timer::Timer::Timer(const std::string& name, TimerTask* task)
: name_(name)
, task_(task)
, state_lock_()
- , delegate_(this, state_lock_)
- , thread_(threads::CreateThread(name_.c_str(), &delegate_))
+ , delegate_(new TimerDelegate(this, state_lock_))
+ , thread_(threads::CreateThread(name_.c_str(), delegate_.get()))
, single_shot_(true) {
LOG4CXX_AUTO_TRACE(logger_);
DCHECK(!name_.empty());
@@ -64,6 +64,7 @@ timer::Timer::~Timer() {
StopDelegate();
single_shot_ = true;
+ delegate_.release();
DeleteThread(thread_);
DCHECK(task_);
delete task_;
@@ -91,26 +92,26 @@ void timer::Timer::Stop() {
bool timer::Timer::is_running() const {
sync_primitives::AutoLock auto_lock(state_lock_);
- return !delegate_.stop_flag();
+ return !delegate_->stop_flag();
}
timer::Milliseconds timer::Timer::timeout() const {
sync_primitives::AutoLock auto_lock(state_lock_);
- return delegate_.timeout();
+ return delegate_->timeout();
}
void timer::Timer::StartDelegate(const Milliseconds timeout) const {
- delegate_.set_stop_flag(false);
- delegate_.set_timeout(timeout);
+ delegate_->set_stop_flag(false);
+ delegate_->set_timeout(timeout);
}
void timer::Timer::StopDelegate() const {
- delegate_.set_stop_flag(true);
- delegate_.set_timeout(0);
+ delegate_->set_stop_flag(true);
+ delegate_->set_timeout(0);
}
void timer::Timer::StartThread() {
- if (delegate_.finalized_flag()) {
+ if (delegate_->finalized_flag()) {
return;
}
@@ -121,18 +122,18 @@ void timer::Timer::StartThread() {
}
void timer::Timer::StopThread() {
- if (delegate_.finalized_flag()) {
+ if (delegate_->finalized_flag()) {
return;
}
DCHECK_OR_RETURN_VOID(thread_);
if (!thread_->IsCurrentThread()) {
- delegate_.set_finalized_flag(true);
+ delegate_->set_finalized_flag(true);
{
sync_primitives::AutoUnlock auto_unlock(state_lock_);
thread_->join();
}
- delegate_.set_finalized_flag(false);
+ delegate_->set_finalized_flag(false);
}
}