Archive: System plugin + widestring -> GPF/SEGFAULT


System plugin + widestring -> GPF/SEGFAULT
In the GetAdministrators function of the NSIS-RunAs dll I implemented, I return an allocated array of widestrings.
With the pointer to that array put in $2, I do the following sequence to get the resulting strings:

[count = number of strings]
loop:
[if count = 0] Goto endloop
System::Call '*$2(w .r3)'
[useful code to treat $3]
System::Free $3
IntOp $2 $2 + 4
[count--]
Goto loop
endloop:
System::Free $2

At the first iteration, the code works properly. At the second iteration, the installer program crashes.
When I treat the string as bytechar strings, I don't have that problem. But of course I only get the first character of each so it's not useful but it let me know that the strings are well returned.

Now, when I invoke wprintf in each of those strings before returning them, the crash does not occur, which looks a bit like voodoo to me.

Just so you know. The strings are allocated/copied with wcsdup().

Since I am not used to Win32 programming and I don't know the System plugin's internals, could someone help me with that?


Thanks


Wolfgang


You are freeing the strings and the array using a different method than the method used to allocate them. System::Free uses GlobalFree and wcsdup probably uses malloc. Have another function for your plug-in that frees the array. You should always have the same component both allocate and free the memory unless there's a set method for allocation known by everyone.