From c2a90f41f0e7d27834b9ee3f10cdd4b116e67a3f Mon Sep 17 00:00:00 2001
From: Marius Greuel <greuelm@mgtek.com>
Date: Wed, 4 Jan 2023 18:02:01 +0100
Subject: [PATCH] Set MSVC readline version to 0x0502, some cleanup

---
 src/msvc/readline.cpp | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/msvc/readline.cpp b/src/msvc/readline.cpp
index 786bf247..4fed1b1e 100644
--- a/src/msvc/readline.cpp
+++ b/src/msvc/readline.cpp
@@ -13,9 +13,8 @@
 #include "readline/readline.h"
 #include "readline/history.h"
 
-int rl_readline_version = 0x0500;
+int rl_readline_version = 0x0502;
 
-static char* rl_prompt;
 static rl_vcpfunc_t* rl_handler;
 static std::unique_ptr<std::thread> rl_thread;
 static std::mutex rl_mutex;
@@ -34,8 +33,11 @@ static void get_line_thread()
 
 static void call_handler(const char* string)
 {
-    rl_thread->join();
-    rl_thread = nullptr;
+    if (rl_thread)
+    {
+        rl_thread->join();
+        rl_thread = nullptr;
+    }
 
     if (rl_handler != nullptr)
     {
@@ -78,19 +80,13 @@ void rl_callback_read_char(void)
 
 void rl_callback_handler_install(char* prompt, rl_vcpfunc_t* handler)
 {
-    rl_prompt = _strdup(prompt);
     rl_handler = handler;
 
-    std::cout << rl_prompt;
+    std::cout << prompt;
 }
 
 void rl_callback_handler_remove(void)
 {
-    if (rl_prompt != nullptr)
-    {
-        free(rl_prompt);
-    }
-
     rl_handler = nullptr;
 }