Memory Leak UTF-8 mode Select Case Case

Windows specific questions.
Post Reply
fbfans
Posts: 17
Joined: Nov 27, 2023 0:29

Memory Leak UTF-8 mode Select Case Case

Post by fbfans »

Code: Select all

Dim c As String 
c = "abc"
do While True 
   Select Case c
      Case "a"
      Case "B" 
   End Select 
Loop 
replace case "a" case "b" with case str("a") case str("B") is OK!
Last edited by fbfans on Jan 19, 2024 18:43, edited 1 time in total.
SARG
Posts: 1768
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Memory leak

Post by SARG »

No difference in both cases : infinite loop as impossible to get out.

Code: Select all

Dim c As String
c = "abc"
do While True
Select Case c
Case "a"
Case "B"
End Select
print "ee",time
Loop
fxm
Moderator
Posts: 12132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Memory leak

Post by fxm »

I also do not see any memory leaks.
fbfans
Posts: 17
Joined: Nov 27, 2023 0:29

Re: Memory leak

Post by fbfans »

save code to utf-8 mode, and compile it.
I'm sorry my English is poor :x
fbfans
Posts: 17
Joined: Nov 27, 2023 0:29

Re: Memory leak

Post by fbfans »

fxm wrote: Jan 19, 2024 9:39 I also do not see any memory leaks.
It only appears when compiling in UTF-8 file format, and ANSI is normal
adeyblue
Posts: 300
Joined: Nov 07, 2019 20:08

Re: Memory Leak UTF-8 mode Select Case Case

Post by adeyblue »

The genreated code for the case checks

Code: Select all

	{
		{
			uint16* TMP$4$2;
			uint16* vr$3 = fb_StrToWstr( (uint8*)*(uint8**)&C$0 ); '' convert the select case string to wstr
			TMP$4$2 = vr$3;
			int32 vr$4 = fb_WstrCompare( (uint16*)TMP$4$2, (uint16*)L"a" ); '' check against case value
			if( (vr$4 != 0) ) goto label$5; '' if not equal, go to next case
			fb_WstrDelete( (uint16*)TMP$4$2 ); '' delete the converted string. Doesn't happen if they're not equal

		}
	}
Oopsy. Similarly happens with a 'normal' ascii file if you make the cases WStr

Code: Select all

Dim c As String 
 c = "abc"
 do While True 
 Select Case c
 Case WStr("a")
 Case WStr("B") 
 End Select 
 Loop 
fbfans
Posts: 17
Joined: Nov 27, 2023 0:29

Re: Memory Leak UTF-8 mode Select Case Case

Post by fbfans »

adeyblue wrote: Jan 21, 2024 6:18 The genreated code for the case checks

Code: Select all

	{
		{
			uint16* TMP$4$2;
			uint16* vr$3 = fb_StrToWstr( (uint8*)*(uint8**)&C$0 ); '' convert the select case string to wstr
			TMP$4$2 = vr$3;
			int32 vr$4 = fb_WstrCompare( (uint16*)TMP$4$2, (uint16*)L"a" ); '' check against case value
			if( (vr$4 != 0) ) goto label$5; '' if not equal, go to next case
			fb_WstrDelete( (uint16*)TMP$4$2 ); '' delete the converted string. Doesn't happen if they're not equal

		}
	}
Oopsy. Similarly happens with a 'normal' ascii file if you make the cases WStr

Code: Select all

Dim c As String 
 c = "abc"
 do While True 
 Select Case c
 Case WStr("a")
 Case WStr("B") 
 End Select 
 Loop 
Yes, the same result
fxm
Moderator
Posts: 12132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Memory Leak UTF-8 mode Select Case Case

Post by fxm »

adeyblue wrote: Jan 21, 2024 6:18 Oopsy. Similarly happens with a 'normal' ascii file if you make the cases WStr

Code: Select all

Dim c As String 
 c = "abc"
 do While True 
 Select Case c
 Case WStr("a")
 Case WStr("B") 
 End Select 
 Loop 
Well seen !
A bug report also with this last code is more demonstrative for this memory leak.
fxm
Moderator
Posts: 12132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Memory Leak UTF-8 mode Select Case Case

Post by fxm »

fxm
Moderator
Posts: 12132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Memory Leak UTF-8 mode Select Case Case

Post by fxm »

linked with STRING Join BUG ?
SARG
Posts: 1768
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Memory Leak UTF-8 mode Select Case Case

Post by SARG »

The memory leak is due to a missing delete for the temporary Wstrings (created at each loop and case) used when testing 'c' string and wstr("a").
If the CASE is true the delete occurs but not if false.

Not the same issue with 'string join bug' even it seems there is also a memory leak (Need to talk with jeff).
Post Reply