Bug 6347

Kernel32 LocalFree function crashes PB 2019 06 April, 2021

Marco Meoni
25 March, 2021
Product: PowerBuilder Category: Other
Version: 2019 Build: R1 R2 R3 and 2021
Classification: Sybase (legacy) bug Publishing: Public
Priority: P3
Status: Scheduling Reason:
Mark Lee @Appeon 06 April, 2021
#10
Hello Marco,

Thanks for your feedback.
I think you are right.  And I will escalate this problem to our development team for further analysis. 
We will need some time to figure it out and we will get back to you if any progress we would make.

Regards,
Mark Lee
Marco Meoni 04 April, 2021
#9
Hello Mark,
thanks for your feedback.
I’m surprised such minimal testcase results in 3 different outcomes:
- works in PB 12.x only (Marco)
- works also in PB 2019 (Chris)
- never works (Mark)
I think the key point is whether the reason of the crash of PB 2019 can be fixed.
Best,
.m
Mark Lee @Appeon 01 April, 2021
#8
Hello Marco,
 
Thanks for reporting this problem and providing the test case.
I can reproduce this crash issue on our side with PB 2019 R3 IDE and PB 12.6 IDE. But I also found that PB 12.5 IDE doesn't have the same behavior.
 
We further analyzed & discussed it with the development team and found that the crash code (lnv_KERNEL.LocalFree(lstr_userinfo.wkui1_logondomain) is not required, it should be commented out or deleted.
 
The variable ll_addressuserinfo in the code you provided will create memory via NetWkstaUserGetInfo API, so you need to use the LocalFree function to release it. However, for the variable lstr_userinfo.wkui1_logondomain, it just copies the contents of a source memory block, it is not that your code create the memory, so you don't need to use the LocalFree function to release it and PB will auto manage it via the lstr_userinfo structure. 
https://docs.microsoft.com/en-us/windows/win32/devnotes/rtlmovememory 

Regards,
Mark Lee
Marco Meoni 31 March, 2021
#7
Hello Support Team,
have you been able to reproduce the issue and see PB IDE crashing?
Thanks for your collaboration!
Best,
.m
Chris Pollach @Appeon 26 March, 2021
#6
Hi Marco;

 Your Test Case crashed for me but after the change to the "RtlMoveMemory" SDK declaration the Test Case worked 100% for me each time. AFAIK, the LocalFree crash is just a side effect of the other SDK calls that then causes memory size / boundary instability.

 FWIW: I am testing on W10 version 20H2 build 19042.867
       Also, PB 12.6 introduced the byte / word memory alignment change

 I will now transfer this ticket over to the main Support Team for their review & feedback on this issue. They might have some better diagnostic tools to see if any other related issue(s) is causing the LocalFree issue.

Regards ... Chris
Marco Meoni 26 March, 2021
#5
localfree.mov.zip (1066KB)

Hi Chris,
thanks for your feedback.

1) did you run the test case in PB 2019? Your version crashes  as well on my side, see short recording attached.
2) LocalFree is KERNEL32.DLL function, it is different from RtlMoveMemory that you modified. First one is declared in n_cst_kernel32 NVO and doesn't come with ;ANSI.
3)I don't think Unicode is the issue, PB 12.5 was Unicode already. The ;ANSI designation must be used in functions with String arguments, which is not the case of LocalFree(), nor RtlMoveMemory().

Cheers,
.m
Chris Pollach @Appeon 25 March, 2021
#4
Screen capture by Chris
Chris Pollach @Appeon 25 March, 2021
#3
Hi Marco;

  I see that your "LocalFree" external function is just calling the MS-Windows "RtlMoveMemory" SDK command. I checked in my STD Framework and I do similar things with this SDK command but I have never used the ";ANSI" designation since way back before PB 10.x (ANSI) and after that PB went Unicode.

  I modified your test case (see attached) to define the two external functions without any ";ansi" qualifiers, for example ...

Function long PutUserInfo(REF WKSTA_USER_INFO_1 Source,ulong Destination, long Size) library "kernel32.dll" Alias For "RtlMoveMemory"
Function long PutLocalGroupUserInfo(REF LOCALGROUP_USERS_INFO_0 Source,ulong Destination, long Size) library "kernel32.dll" Alias For "RtlMoveMemory"

  Once I did that, your Test Case worked 100% every time (see test screen capture attached). Please try my updated test case and see how that now works for you. My test case is working for me in PB 2019 R2/R3 & PB2021.

HTH
Regards ... Chris
Chris Pollach @Appeon 25 March, 2021
#2
Test Case (By Chris)
Marco Meoni 25 March, 2021
#1
TestCase.zip (46KB)

*Phenomenon:
Customer is migrating a legacy app from PB 12.x to PB 2019 R2/R3.
Full rebuild completed but app closing suddenly, no error.
Debugged the code and isolated the line causing the crash.
It is LocalFree() function from kernel32.dll, which works fine in PB 12.x.

*Reproduce Steps:
Attached a PB 12.5 testcase reproducing the issue, just 1 button with simple script.
It works in PB 12.x.
But it crashes when executed from any PB 2019 or 2021 Beta. 
It is not just the app EXE crashing, but the entire PB IDE.

Best regards,
.m
OS:
Windows 10
Platform:
64-bit
Database Type:
Database Version: