From dc277003a2f2e5e0090b1c6a325cbfb7c68cec11 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 15 May 2017 20:19:21 +0430 Subject: the memory leak is apparently a non-issue, for more info read the comment in the source code for it --- bruiser/CompletionHints.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'bruiser') diff --git a/bruiser/CompletionHints.cpp b/bruiser/CompletionHints.cpp index ed0eb2e..43f4345 100644 --- a/bruiser/CompletionHints.cpp +++ b/bruiser/CompletionHints.cpp @@ -63,15 +63,17 @@ namespace bruiser break; } - if (iter.find(dummy) == 0U) + if (iter.find(__buf) == 0U) { *__color = 35; - *__bold = 0; + *__bold = 1; int sizet = dummy.length(); - std::string dummy2 = iter.substr(sizet, iter.length() - sizet + 1); + std::string dummy2 = iter.substr(sizet, std::string::npos); - /*LEAKS MEMORY*/ + /*@DEVI-apparently linenoise expects the return value to live past the hints callback function returning, + * i mean that's why our vector version returns junk. linenoise later frees the returned hint so there + * should be no leaked memory(it calls freeHintsCallback).*/ char* returnchar = new char[dummy2.size() + 1]; std::copy(dummy2.begin(), dummy2.end(), returnchar); returnchar[dummy2.size()] = '\0'; @@ -81,12 +83,13 @@ namespace bruiser retchar.push_back('\0'); //std::cout << "\n" << retchar.data() << "\n"; char* c = (char*)retchar.data(); - //std::cout << "\n" << c << "\n"; + std::cout << "\n" << c << "\n"; #endif return returnchar; //return c; - //return &*retchar.data(); + //return retchar.data(); + //return &retchar[0]; } } } -- cgit v1.2.3