Help with AREXX in a C program

This forum is for general developer support questions.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Help with AREXX in a C program

Post by xenic »

@tonyw
Since CreateArgString() copies a string then ARexx can dispose of it when you call DeleteArgString(). However, I've seen a lot of ARexx code that just assigns unprocessed strings (not created with CreateArgString) to the argument array (e.g. rexxmsg->rm_Args[0] = "any string") and don't bother to free the results with DeleteArgString(). I'm guessing that a program is responsible for freeing unprocessed assigned argument strings and that strings created with CreateArgString() should be freed with DeleteArgString(). I've looked at the ARexx code in several major programs (Dopus4, YAM etc.) and the result string (result2) is created with CreateArgString() if the comand is successful and set to a failure number if the command failed. That indicates to me that the result string (result2) should be freed with DeleteArgString() if the result1 code is 0 (indicating success). It seems like there could be a lot of unfreed result strings could be left in the system by programs that don't free the result strings.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: Help with AREXX in a C program

Post by thomasrapp »

xenic wrote:I've seen a lot of ARexx code that just assigns unprocessed strings (not created with CreateArgString) to the argument array (e.g. rexxmsg->rm_Args[0] = "any string") and don't bother to free the results with DeleteArgString().
That's what FillRexxMsg / ClearRexxMsg are for.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: Help with AREXX in a C program

Post by xenic »

thomasrapp wrote:That's what FillRexxMsg / ClearRexxMsg are for.
I see that those functions are used in your example and the autodocs state that ClearRexxMsg() will DeleteArgString() multiple argstrings from the RexxMsg. I collect all the sourcecode I can find and the problem with not freeing arguments was in other example code; not yours.

However, I see in your example that the result2 string is not freed with DeleteArgString(). As I mentioned before, the replying program has no way of knowing when the receiver of the reply is finished with a result2 string and I assume that it would be the responsibility of the original message sender to free a result string.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Help with AREXX in a C program

Post by broadblues »

However, I see in your example that the result2 string is not freed with DeleteArgString().
This is an error the result2 string *should* be freed with DeleteArgstring() by the program sending the message. The Function Host *must* allocate this string with CreateArgstring()

ARexx would leak memory like a seive is this was not so.
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: Help with AREXX in a C program

Post by thomasrapp »

broadblues wrote:This is an error
Fixed.
Post Reply