Hi group, got a question on global arrays that may be causing problems.

 In globals.h, I have one defined as

            extern char *sourcelist[100];

In main.c, I declare it, and initialize it:

           char *sourcelist[]  = {0};    // there's probably a better way


I use this array of char pointers everywhere, in all of my c files, of
course.


 In mainforminit(), I fill it up with some srings,

             sourcelist[index] = MemPtrNew(StrLen(theCat.catname) + 1);
             StrCopy( sourcelist[index], theCat.catname );
                               // ( theCat contains a structure just
retrieved from
                               // database, and catname is a string of
course )


And in other modules, I'll do things like erase one of the elements in the
array with
memptrfree, and then call MemPtrNew to reallocate and throw another string
in there, etc...

When my app is closed, I have a deAllocSource function that loops through
the array of pointers, and calls
MemPtrFree on every one, but I'm still intermittenly getting memory leakage
errors when closing my app on the
debug ROM. (using new POSE version, which tells me where I'm allocating the
part of the memory that is leaking, but I still can't find the problem
anyway)


void deAllocSource()
{
    UInt16 index ;
    UInt16 err;
     char a[100];

       for (index = 0; index < g_source_array_count; index++)
    {

      err = MemPtrFree(sourcel[index]);
      ErrFatalDisplayIf(err, "problem with memptrfree'ing one of the sourcel
array members");
      err = MemPtrFree(sourcelist[index]);
      ErrFatalDisplayIf(err, "problem with memptrfree'ing one of the source
strings");


    }
      g_source_array_count = 0;
      return;
}


Do you see a problem with using an array of pointers as a global variable
like this?

Thanks for reading this, would appreciate a hint if you have one
Steve
 p.s., using PALMOS 3.5 sdk with CW 6.0

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to