From 62b3466160499345eb3bdcd1fa9a77500dbdeecd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?=
 =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?=
 <erik@darapsa.co.id>
Date: Fri, 19 May 2023 17:21:13 +0800
Subject: Options might be gone at libinterchange

---
 interchange.cxx | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/interchange.cxx b/interchange.cxx
index c8c6a6e..1e3fc90 100644
--- a/interchange.cxx
+++ b/interchange.cxx
@@ -6,6 +6,7 @@ namespace QInterchange {
 	static Interchange* interchange;
 	static int sampleUrlLength = 0;
 	static char *mv_sku = nullptr, *mv_order_item = nullptr;
+	static QVector<const char *> pointers;
 
 	Interchange::Interchange(const char* sampleURL, const char* image_Dir,
 			const QString& cookie, const QString& certificate)
@@ -88,10 +89,16 @@ namespace QInterchange {
 		const char *mv_order_s[size + 1][2];
 		for (int i = 0; i < size; i++) {
 			auto pair = opts.at(i).toList();
-			mv_order_s[i][0] = pair.at(0)
-				.toByteArray().constData();
-			mv_order_s[i][1] = pair.at(1)
-				.toByteArray().constData();
+			auto key = pair.at(0).toByteArray();
+			mv_order_s[i][0] = (const char *)malloc(key.size() + 1);
+			strcpy(const_cast<char *>(mv_order_s[i][0]),
+					key.constData());
+			pointers.append(mv_order_s[i][0]);
+			auto val = pair.at(1).toByteArray();
+			mv_order_s[i][1] = (const char *)malloc(val.size() + 1);
+			strcpy(const_cast<char *>(mv_order_s[i][1]),
+					val.constData());
+			pointers.append(mv_order_s[i][1]);
 		}
 		mv_order_s[size][0] = nullptr;
 		interchange_ord_order(mv_sku, mv_order_item, quantity,
@@ -100,6 +107,7 @@ namespace QInterchange {
 			mv_sku = nullptr;
 			free(mv_order_item);
 			mv_order_item = nullptr;
+			for (auto pointer : pointers) free((void *)pointer);
 			interchange->emitOrder(QString{response->data});
 			interchange_free_response(response);
 		});
-- 
cgit v1.2.3