diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-07-20 07:45:31 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-07-23 11:22:43 -0700 |
commit | 16b31985c3245d5cb3be26f3cc0aa06bc6acb139 (patch) | |
tree | 972684866d5ec71781fbf91f990bea83a654ecad /core | |
parent | f142e9a9c6ba493c09a282544da8715b3656648e (diff) | |
download | subsurface-16b31985c3245d5cb3be26f3cc0aa06bc6acb139.tar.gz |
cleanup: replace membuffer by membufferpp in C-code
Thus, the membuffer data is automatically freed when going
out of scope - one thing less to worry about.
This fixes one use-after-free bug in uploadDiveLogsDE.cpp
and one extremely questionable practice in divetooltipitem.cpp:
The membuffer was a shared instance across all instances
of the DiveToolTipItem.
Remves unnecessary #include directives in files that didn't
even use membuffer.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divesitehelpers.cpp | 1 | ||||
-rw-r--r-- | core/qthelper.cpp | 1 | ||||
-rw-r--r-- | core/uploadDiveLogsDE.cpp | 9 | ||||
-rw-r--r-- | core/uploadDiveShare.cpp | 3 |
4 files changed, 4 insertions, 10 deletions
diff --git a/core/divesitehelpers.cpp b/core/divesitehelpers.cpp index bb4764274..5a36d63ca 100644 --- a/core/divesitehelpers.cpp +++ b/core/divesitehelpers.cpp @@ -9,7 +9,6 @@ #include "errorhelper.h" #include "subsurface-string.h" #include "qthelper.h" -#include "membuffer.h" #include <QDebug> #include <QJsonDocument> #include <QJsonArray> diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 185e46bbc..d14276031 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -7,7 +7,6 @@ #include "subsurface-string.h" #include "gettextfromc.h" #include "statistics.h" -#include "membuffer.h" #include "version.h" #include "errorhelper.h" #include "planner.h" diff --git a/core/uploadDiveLogsDE.cpp b/core/uploadDiveLogsDE.cpp index 6dc764ed1..980800149 100644 --- a/core/uploadDiveLogsDE.cpp +++ b/core/uploadDiveLogsDE.cpp @@ -97,7 +97,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected) const char *membuf; xmlDoc *transformed; struct zip_source *s; - struct membuffer mb = {}; + struct membufferpp mb; struct xml_params *params = alloc_xml_params(); /* @@ -109,9 +109,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected) continue; } - /* make sure the buffer is empty and add the dive */ - mb.len = 0; - + /* add the dive */ struct dive_site *ds = dive->dive_site; if (ds) { @@ -140,7 +138,7 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected) put_format(&mb, "</divelog>\n"); } membuf = mb_cstring(&mb); - streamsize = strlen(membuf); + streamsize = mb.len; /* * Parse the memory buffer into XML document and * transform it to divelogs.de format, finally dumping @@ -156,7 +154,6 @@ bool uploadDiveLogsDE::prepareDives(const QString &tempfile, bool selected) free_xml_params(params); return false; } - free_buffer(&mb); xml_params_add_int(params, "allcylinders", prefs.display_unused_tanks); transformed = xsltApplyStylesheet(xslt, doc, xml_params_get(params)); diff --git a/core/uploadDiveShare.cpp b/core/uploadDiveShare.cpp index 8d5858e00..87c3d0b24 100644 --- a/core/uploadDiveShare.cpp +++ b/core/uploadDiveShare.cpp @@ -27,10 +27,9 @@ uploadDiveShare::uploadDiveShare(): void uploadDiveShare::doUpload(bool selected, const QString &uid, bool noPublic) { //generate json - struct membuffer buf = {}; + struct membufferpp buf; export_list(&buf, NULL, selected, false); QByteArray json_data(buf.buffer, buf.len); - free_buffer(&buf); //Request to server QNetworkRequest request; |