From 16b31985c3245d5cb3be26f3cc0aa06bc6acb139 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 20 Jul 2021 07:45:31 +0200 Subject: 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 --- core/divesitehelpers.cpp | 1 - core/qthelper.cpp | 1 - core/uploadDiveLogsDE.cpp | 9 +++------ core/uploadDiveShare.cpp | 3 +-- 4 files changed, 4 insertions(+), 10 deletions(-) (limited to 'core') 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 #include #include 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, "\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; -- cgit v1.2.3-70-g09d2