[Done] PureBasic 6.40 alpha 2 - memory leak in API
Posted: Wed Jan 28, 2026 4:30 pm
A bug similar to this but with fixed strings.Function SYS_CopyFixedString() returns a pointer to the string, but the string is not freed.
Similar memory leak with other API functions, for example MessageBox.
Code: Select all
Procedure Test()
Protected Semaphore.s{#MAX_PATH}="Semaphore"
For i=0 To 10000000
CreateSemaphore_(#Null, 0, 1, Semaphore)
Next
EndProcedure
Test()
MessageRequester("","")Code: Select all
// Procedure Test()
static integer f_test() {
integer r=0;
unsigned short v_semaphore[260]={0};
integer v_i=0;
// Protected Semaphore.s{#MAX_PATH}="Semaphore"
SYS_AssignFixedStringFast(v_semaphore,260,&_S2[4]);
// For i=0 To 10000000
v_i=0;
while(1) {
if (!(((integer)10000000LL>=v_i))) { break; }
// CreateSemaphore_(#Null, 0, 1, Semaphore)
integer r0=f_createsemaphore_(0LL,0LL,1LL,SYS_CopyFixedString(v_semaphore,260)); <---- Memory leak
// Next
next1:
v_i+=1;
}
il_next2:;
// EndProcedure
r=0;
end:
return r;
}Similar memory leak with other API functions, for example MessageBox.
Code: Select all
PureBasicPath${#MAX_PATH}
GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
MessageBox_(0, PureBasicPath$, ""+Len(PureBasicPath$), 0)Code: Select all
// PureBasicPath${#MAX_PATH};
// GetModuleFileName_(GetModuleHandle_(#Null$), @PureBasicPath$, #MAX_PATH)
integer r0=f_getmodulehandle_(0);
integer r1=f_getmodulefilename_(r0,((integer)v_purebasicpathS),260LL);
// MessageBox_(0, PureBasicPath$, ""+Len(PureBasicPath$), 0)
integer r2=PB_Len(SYS_CopyFixedString(v_purebasicpathS,260));
void *r3=PB_Str(r2);
s1=SYS_ConcatString(r3,SYS_Empty);
integer r4=f_messagebox_(0LL,SYS_CopyFixedString(v_purebasicpathS,260),s1,0LL); <---- Memory leak
SYS_FreeTemporaryString(s1);