Sign in Join

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

Mailing lists / fpc-pascal / 2012-01

memory corruption

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

ik

Hello,

While testing my following code:
https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L166

When I'm executing the code on the second item (that is suppose to be null in the protocol -> '$-1#13#10'),
the program crashes with the following message:
*** glibc detected *** redis_client/tests/test_parser: malloc(): memory corruption (fast): 0x0000000000750d50 ***

Using gdb to display the information seems that the following like: https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L85is the cause.
It looks like accessing either tmps or ALine[j] is causing it.

I can't figure out the reason for it.

I'm using FPC 2.6.0 x86_64 on Archlinux.

What am I missing here ?

Thanks,
Ido

Reply by email

Michael Müller
to ik
ik wrote 12 lines
Hello, While testing my following code: https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L166 When I'm executing the code on the second item (that is suppose to be null in the protocol -> '$-1#13#10'), the program crashes with the following message: *** glibc detected *** redis_client/tests/test_parser: malloc(): memory corruption (fast): 0x0000000000750d50 *** Using gdb to display the information seems that the following like: https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L85 is the cause. It looks like accessing either tmps or ALine[j] is causing it.

I would expect that already line 83 is the problem. You have to change the order of the statements otherwise you'll access a not existing element in ALine before checking if the index is already to big when j becomes > alength. So change
while (ALine[j] #13) and (j <= alength) do
into
while (j <= alength) and (ALine[j] #13) do

But this will only work if the compiler switch {$B-} (verbose version {$BOOLEVAL OFF}) is set which is the default in Delphi so I assume the same in FPC too.
If you can't ensure that you should do it like this
while (j <= alength) do
  if (ALine[j]  #13) then

Regards

Michael

Reply by email

ik
to Michael Müller

On Thu, Jan 26, 2012 at 09:10, Michael Müller <

Show quoted text 39 lines
wrote: Am 26.01.2012 um 03:50 schrieb ik: Hello, While testing my following code: https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L166 When I'm executing the code on the second item (that is suppose to be null in the protocol -> '$-1#13#10'), the program crashes with the following message: *** glibc detected *** redis_client/tests/test_parser: malloc(): memory corruption (fast): 0x0000000000750d50 *** Using gdb to display the information seems that the following like: https://github.com/ik5/redis_client.fpc/blob/master/tests/test_parser.lpr#L85is the cause. It looks like accessing either tmps or ALine[j] is causing it. I would expect that already line 83 is the problem. You have to change the order of the statements otherwise you'll access a not existing element in ALine before checking if the index is already to big when j becomes > alength. So change while (ALine[j] #13) and (j <= alength) do into while (j <= alength) and (ALine[j] #13) do But this will only work if the compiler switch {$B-} (verbose version {$BOOLEVAL OFF}) is set which is the default in Delphi so I assume the same in FPC too. If you can't ensure that you should do it like this while (j <= alength) do if (ALine[j] #13) then

Thanks,
I used valgrind and discovered this:
==20532== at 0x458754:
RD_TYPES_TREDISMULTIBULKRETURNTYPE_$__INSERT$LONGINT$TREDISRETURNTYPE (rd_types.pas:406)

It was off by one else where. Why does it take such time to effect the executable ?

Show quoted text 5 lines
Regards Michael

Ido

Show quoted text 5 lines
_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email