From: shulick@navajo.ucs.indiana.edu (Sam Hulick)
Newsgroups: comp.sys.amiga.programmer
Subject: Please help with stupid memory leak
Date: 7 Jan 93 23:43:26 GMT
Reply-To: shulick@navajo.ucs.indiana.edu
Organization: Vallen Software
Originator: shulick@navajo


I can't figure this one out.  It seems to not free either 56 bytes or
296.  Anyway, the usage is:  req <title> <text> <choice1> [choice]...
Some examples:
  req Problem "There's a bug in here." "Kill it" "Hang it" Cancel

Well, it doesn't free up memory, but I can't figure out WHAT.. any help
would be appreciated.

/* req.c - Use system requests in scripts */
/* This is free.  Copy it, sell it, eat it, reprogram it, eat it.  No one
   gives a crap. :)
Notice, you can customize what sort of output you want.  If you want, you can
convert the values into something else and pass them to exit(), or you can
just print them out (as I have here).  See doc for more info on usage. */
/* BTW - it's messy, but it works.  Reprogram if you want. */

#include <stdio.h>
#include <intuition/intuition.h>
#include <dos/rdargs.h>
#include <exec/alerts.h>

#include <clib/dos_protos.h>
#include <clib/exec_protos.h>

/* All we need is one.. */
struct EasyStruct ereq = {
   sizeof(struct EasyStruct), 0,  /* unimportant stuff */
   NULL,  /* Title of requester */
   NULL,  /* Text */
   NULL   /* Choices */
};  /* of course, these will be filled in later, by the user */

struct Library *IntuitionBase=NULL;
LONG arr[4];
char workstr2[BUFSIZ], sigh[BUFSIZ];
struct RDArgs *rd=NULL;

void bye();

void main(int ac, char **av)
{
   int x, len;
   char workstr[BUFSIZ];

   memset(arr, '\0', sizeof(arr));
   /* Oh, ReadArgs() is so nice.. :) */
   if (!(rd = ReadArgs("Title/A,Text/A,Choice1/A,Choices/F", arr, NULL)))
   {
      fprintf(stderr, "required argument missing\n");
      bye();
   }

   if (!(IntuitionBase = OpenLibrary("intuition.library", 37)))
   {
      fprintf(stderr, "Can't open intuition.library V37\n");
      bye();
   }

   if (!(ereq.es_Title = (UBYTE *)malloc(strlen((char *)arr[0])+1)))
   {
      Alert(AT_Recovery | AG_NoMemory);
      exit(0);
   }
   ereq.es_Title = (UBYTE *)arr[0];
   strcpy(workstr, arr[3]); /* Because we can't do arr[3][x] */
   len = strlen(workstr);
   for (x = 0; x < len; ++ x)
   {
      if (workstr[x] == ' ')
         workstr[x] = '|';
   }
   strcpy(workstr2, arr[1]);
   len = strlen(workstr2);
   for (x = 0; x < len; ++ x)
   {
      if (workstr2[x] == '\\')
         workstr[x] = '\n';
   }
   if (!(ereq.es_TextFormat = (UBYTE *)malloc(strlen((char *)workstr2)+1)))
   {
      Alert(AT_Recovery | AG_NoMemory);
      exit(0);
   }
   ereq.es_TextFormat = (UBYTE *)workstr2;
   /* sprintf()'ing into 'sigh' is easier than malloc()'ing GadgetFormat */
   /*  :)  */
   if (workstr[0])
      sprintf(sigh, "%s\|%s", (char *)arr[2], workstr);
   else
      strcpy(sigh, (char *)arr[2]);
   if (!(ereq.es_GadgetFormat = (UBYTE *)malloc(strlen((char *)sigh)+1)))
   {
      Alert(AT_Recovery | AG_NoMemory);
      exit(0);
   }
   ereq.es_GadgetFormat = (UBYTE *)sigh;
   printf("%d\n", EasyRequest(NULL, &ereq, NULL));

   bye();
}

void bye()
{
   free(ereq.es_TextFormat);
   free(ereq.es_GadgetFormat);
   free(ereq.es_Title);
   if (IntuitionBase)
      CloseLibrary(IntuitionBase);
   exit(0);
}
-- 
    // Amiga 3000   ___ \ Sam Hulick: shulick@indiana.edu (NeXTmail OK!)
   // 68030 25 MHz /__/\ \ My opinions wear combat boots.  Or whatever.
\\// OS 2.04       \__\/ / "Walk!  Not bloody likely.  I am going in a
 \/                     / taxi."  --George Bernard Shaw
Newsgroups: comp.sys.amiga.programmer