Skip to content

Commit 3e8d261

Browse files
author
Food Tiny
authored
Merge pull request #70 from foodtiny/task/fix-memory-leak
[java.lang.String] Fixed typo 'reversedString'
2 parents e565be9 + 208d00c commit 3e8d261

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

java/lang/String/String.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,14 @@ int String::lastIndexOf(int ch, int fromIndex) {
302302
* @return int
303303
*/
304304
int String::lastIndexOf(String str) const {
305-
string strReversed = string_reverse(str.toString());
306-
string currentStrReversed = string_reverse(this->toString());
307-
308-
int result = string_index(currentStrReversed, strReversed, 1);
309-
310-
free(strReversed);
311-
free(currentStrReversed);
312-
305+
string reversedString = string_reverse(str.toString());
306+
string currentReversedString = string_reverse(this->toString());
307+
int result = string_index(currentReversedString, reversedString, 1);
308+
free(reversedString);
309+
free(currentReversedString);
313310
if (result == NOT_FOUND) {
314311
return result;
315312
}
316-
317313
//Re-calculate first character of str
318314
result = this->size - ( result + str.size );
319315
return result;
@@ -328,20 +324,15 @@ int String::lastIndexOf(String str) const {
328324
*/
329325
int String::lastIndexOf(String str, int fromIndex) const {
330326
string subString = &( this->original )[ fromIndex ]; // get subString start fromIndex
331-
332-
string strReversed = string_reverse(str.toString());
333-
string currentStrReversed = string_reverse(subString);
334-
335-
int result = string_index(currentStrReversed, strReversed, 1);
336-
337-
free(strReversed);
338-
free(currentStrReversed);
339-
327+
string reversedString = string_reverse(str.toString());
328+
string currentReversedString = string_reverse(subString);
329+
int result = string_index(currentReversedString, reversedString, 1);
330+
free(reversedString);
331+
free(currentReversedString);
340332
if (result == NOT_FOUND) {
341333
return result;
342334
}
343-
344-
//Re-calculate first character of str
335+
// Re-calculate first character of str
345336
result = this->size - ( result + str.size );
346337
return result;
347338

0 commit comments

Comments
 (0)