#include <exec/memory.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>

FreeStartup(msg)
struct WBStartup *msg;
{
	/* Free the files. Assumes they have been allocated via Launch, so
	 * they're just AllocMemmed. UnLock all the Locks, and Free the
	 * names.
	 */
	if(msg->sm_ArgList) {
		int i;
		for(i = 0; i < msg->sm_NumArgs; i++) {
			if(msg->sm_ArgList[i].wa_Lock)
				UnLock(msg->sm_ArgList[i].wa_Lock);
			if(msg->sm_ArgList[i].wa_Name)
				FreeMem(msg->sm_ArgList[i].wa_Name,
					strlen(msg->sm_ArgList[i].wa_Name)+1);
		}
		FreeMem(msg->sm_ArgList,
			sizeof(struct WBArg) * msg->sm_NumArgs);
	}

	/* Here goes the program...
	 */
	if(msg->sm_Segment)
		UnLoadSeg(msg->sm_Segment);

	/* And the name of the window. Again, assuming it's allocated by
	 * Launch, so it just fits in its AllocMemmed buffer.
	 */
	if(msg->sm_ToolWindow)
		FreeMem(msg->sm_ToolWindow,
			strlen(msg->sm_ToolWindow)+1);

	/* And finally the message itself */
	FreeMem(msg, sizeof(struct WBStartup));
}
