[haiku-development] Re: Fixed obvious memory leak in CLuceneDataBase

  • From: viktor muntzing <viktor.muntzing@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 8 Jan 2016 08:03:47 +0100

Haha, What a first Impression!
I'm totally sorry about that. I also realised today I didn't compile. I
suspect it was around dinner time and I forgot about it.
I've attached a fixed version.

2016-01-08 2:45 GMT+01:00 John Scipione <jscipione@xxxxxxxxx>:



On Thursday, January 7, 2016, looncraz <looncraz@xxxxxxxxxxx> wrote:

On 1/7/2016 19:07, looncraz wrote:


Shouldn't this be:

if (mbstowcs(wStr, str, size) == -1) {
delete[] wStr;
return NULL ;
} else {
return wStr ;
}


Or, more appropriately, not even the else, just return wStr;


Style guide says no {'s on the single line else but you need them around
the multi line if for sure.

From 009896a90e1503cfcdcde6d51b9e9ec0242b95c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Viktor=20M=C3=BCntzing?= <viktor.muntzing@xxxxxxxxx>
Date: Thu, 7 Jan 2016 21:28:45 +0100
Subject: [PATCH] Fixed obvious memory leak in CLuceneDataBase

---
src/add-ons/index_server/fulltext/CLuceneDataBase.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/add-ons/index_server/fulltext/CLuceneDataBase.cpp
b/src/add-ons/index_server/fulltext/CLuceneDataBase.cpp
index e60db9c..4d306e7 100644
--- a/src/add-ons/index_server/fulltext/CLuceneDataBase.cpp
+++ b/src/add-ons/index_server/fulltext/CLuceneDataBase.cpp
@@ -35,9 +35,10 @@ wchar_t* to_wchar(const char *str)
int size = strlen(str) * sizeof(wchar_t) ;
wchar_t *wStr = new wchar_t[size] ;

- if (mbstowcs(wStr, str, size) == -1)
+ if (mbstowcs(wStr, str, size) == -1) {
+ delete[] wStr ;
return NULL ;
- else
+ } else
return wStr ;
}

--
2.5.0

Other related posts: