summaryrefslogtreecommitdiffstats
path: root/message.cpp
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-04-30 17:58:11 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-05-08 19:04:26 -0700
commit3d48372a7d3010e387cff99e5f599ee074be076b (patch)
tree0806546d4835e7850309afb6d61a242f52df68f7 /message.cpp
parent9a0d41d3258697ad16e2eb461e3c7bac0d3e21ff (diff)
libqtappfw: message: fix memory leak with QJsonArray
QJsonArray object was being allocated on the heap and never freed. Switch to having a m_request member field and confirming it is only populated with data once. Change-Id: I60f406eff032650cac878efa7e1db61ee18e2eb2 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'message.cpp')
-rw-r--r--message.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/message.cpp b/message.cpp
index 95bc586..33211da 100644
--- a/message.cpp
+++ b/message.cpp
@@ -29,14 +29,18 @@ Message::Message()
bool Message::createRequest(QString api, QString verb, QJsonValue parameter)
{
- QJsonArray *request = new QJsonArray;
- request->append(Call);
- request->append(9999);
- request->append(api + (QString)("/") + verb);
- request->append(QJsonValue(parameter));
+ if (!m_request.isEmpty()){
+ qWarning("Message instance has already been used. Cannot send another request.");
+ return false;
+ }
+
+ m_request.append(Call);
+ m_request.append(9999);
+ m_request.append(api + (QString)("/") + verb);
+ m_request.append(QJsonValue(parameter));
QJsonDocument jdoc;
- jdoc.setArray(*request);
+ jdoc.setArray(m_request);
m_jdoc = jdoc;
m_init = true;