In our previous episode, Graeme Geldenhuys said:
> 
> I'm working with a C library that returns an array of strings. So that is
> type PPChar.  I C library does the array allocation, but doesn't do the
> freeing of the array.
> 
> How am I supposed to free an array of PChar strings? I think I need to
> improve my iteration too, because I'm moving the pointer of wlst, so I
> probably need to make a backup of the original pointer before the iteration.


The array is 0 terminated, iow the last array of pchar is nil.

var p2 : ppchar;

If assigned(p) then
  begin
    p2:=p;
    while assigned(p2) do 
      begin
        cfree(p2);
        inc(p2);
      end;
    cfree(p);
  end; 

where cfree is the free() corresponding to the malloc with which it was
allocated in the lib. (usually libc's)
 
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to