Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2013-03

problem with TStringLists and delete in glibc

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Stefan Fischer

Hi,

I've get the following error and I don't know how to solve it: *** glibc detected *** ./rfm: free(): invalid pointer: 0xb6d0a01c ***

code-pieces:
##############################################
type
T_IniFileDesc = record

     inifilbuf : TStringList;
     caching,
     blockchange,
     inifildirty,
     inifilavail : boolean;
     inifilename : string;
  end;
var IniFileDescriptor:T_IniFileDesc; name_idx:longint;
...
with IniFileDescriptor do
begin
  inifilbuf:=TStringList.create;
  for name_idx:= 1 to 220 inifilbuf.add('something');
  name_idx:=5;
  inifilbuf.insert (name_idx-1, 'someOTHERstring');
  inifilbuf.delete(name_idx);  // <- this creates the glibc error
end;
##############################################

I'm runnig fpc on:
Free Pascal Compiler version 2.6.0-7+rpi1 [2013/01/23] for arm Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for ARMHF

uname -a gives: Linux raspberrypi 3.6.11+ #393 PREEMPT Fri Mar 8 16:36:28 GMT 2013 armv6l GNU/Linux

Reply by email

Marco van de Voort
to Stefan Fischer

In our previous episode, Stefan Fischer said:

Show quoted text 11 lines
var IniFileDescriptor:T_IniFileDesc; name_idx:longint; ... with IniFileDescriptor do begin inifilbuf:=TStringList.create; for name_idx:= 1 to 220 inifilbuf.add('something'); name_idx:=5; inifilbuf.insert (name_idx-1, 'someOTHERstring'); inifilbuf.delete(name_idx); // <- this creates the glibc error end;

Please write inifilbuf.count after the for-loop.

Maybe tstringlist doesn't store dupes by default, and after the loop it only contains one item.

Reply by email

Stefan Fischer

Hi,
I have 220 strings in the list. Also the code works in a small sample program. I put the code in a unit an used the function in a bigger project with multiple units. In that environment, the code fails in glibc. The content of the string list was the same in both programs. In the small sample it works, in my bigger project it fails. Maybe there is a pointer alignment problem. But for now I really don't know how to trace or debug it.

Mit freundlichen Gruessen / with best regards,

Anfang der weitergeleiteten E‑Mail:

Show quoted text 18 lines
Von: "Mattias Gaertner" An: Betreff: Re: [fpc-devel] problem with TStringLists and delete in glibc On Sat, 16 Mar 2013 15:37:14 +0100 (CET) (Marco van de Voort) wrote: > [...] > Maybe tstringlist doesn't store dupes by default[...] Are you kidding? Mattias _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

waldo kitty
to Stefan Fischer
Stefan Fischer wrote 9 lines
Hi, I have 220 strings in the list. Also the code works in a small sample program. I put the code in a unit an used the function in a bigger project with multiple units. In that environment, the code fails in glibc. The content of the string list was the same in both programs. In the small sample it works, in my bigger project it fails. Maybe there is a pointer alignment problem. But for now I really don't know how to trace or debug it.

reading over the thread and how you moved the functions to a unit for use in a larger program, i'm wondering if there is not an error earlier in the program that is not caught which then shows up at this point...

we used to see something like this all the time back in the TP days when someone would open a file and not check the result codes... then later on they'd get an error on a string or some other function... the problems were always solved by properly checking for errors at those stages where needed...

just my thoughts on it... especially since the smaller program still works properly and the same data is used in both programs...

Reply by email

Stefan Fischer

If I'm not using this piece of code, I have no error. I'm pretty sure that this piece of code generates the error.

Mit freundlichen Gruessen / with best regards,

Anfang der weitergeleiteten E‑Mail:

Show quoted text 30 lines
Von: "waldo kitty" An: Betreff: Re: Fwd: [fpc-devel] problem with TStringLists and delete in glibc On 3/16/2013 11:36, Stefan Fischer wrote: > Hi, > I have 220 strings in the list. Also the code works in a small sample program. > I put the code in a unit an used the function in a bigger project with multiple > units. > In that environment, the code fails in glibc. The content of the string list was > the same in both programs. In the small sample it works, in my bigger project it > fails. > Maybe there is a pointer alignment problem. But for now I really don't know how > to trace or debug it. reading over the thread and how you moved the functions to a unit for use in a larger program, i'm wondering if there is not an error earlier in the program that is not caught which then shows up at this point... we used to see something like this all the time back in the TP days when someone would open a file and not check the result codes... then later on they'd get an error on a string or some other function... the problems were always solved by properly checking for errors at those stages where needed... just my thoughts on it... especially since the smaller program still works properly and the same data is used in both programs... _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email