Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

*** glibc detected *** corrupted double-linked list:

37 views
Skip to first unread message

ghada glissa

unread,
Jun 7, 2015, 11:30:17 AM6/7/15
to
Hi all,

I have a C++ program that I wrote. The code compiles without any error or warning message. But when I execute it, I get

*** glibc detected ***: corrupted double-linked list: 0x000000000564d6f0 ***

Source code:

void Prog:: input_transfo(uint8_t al,uint8_t ml,uint8_t* aa, uint8_t* mm,
uint8_t* Pl, uint8_t* Au){

uint8_t s=0;
uint8_t *ll=new uint8_t[10];

input(al,s,ll);


taille1 = adjust_length(s+al,16);
uint8_t *Add=new uint8_t[taille1];

memcpy(Add,ll,s);
memcpy(Add+s,aa,al);
memcpy(Pl,mm,ml);

taille2 = adjust_length(ml,16);

memcpy(Au,Add,taille1);
memcpy(Au+taille1,Pl,taille2);


delete ll;
delete AddAuthData;

}

void Prog:: auth(uint8_t authlen,uint8_t al,uint8_t ml,uint8_t *n,uint8_t*a,uint8_t *ms,uint8_t *k, uint8_t *MAC){


uint8_t *Pl=new uint8_t[taille2];
uint8_t *Au=new uint8_t[taille1+taille2];

input_transfo(al,ml,a,ms,Pl,Au);


delete PlainData;
delete AuData;
}

taille1 et taille2 are two globale variables
I got this error when i use the second function which uses the first function.

any help please??

Best regards.

Christian Gollwitzer

unread,
Jun 7, 2015, 11:44:19 AM6/7/15
to
Am 07.06.15 um 17:30 schrieb ghada glissa:
> Hi all,
>
> I have a C++ program that I wrote. The code compiles without any error or warning message. But when I execute it, I get
>
> *** glibc detected ***: corrupted double-linked list: 0x000000000564d6f0 ***
>
> Source code:
>
> void Prog:: input_transfo(uint8_t al,uint8_t ml,uint8_t* aa, uint8_t* mm,
> uint8_t* Pl, uint8_t* Au){
>
> uint8_t s=0;
> uint8_t *ll=new uint8_t[10];
>
> input(al,s,ll);
>
>
> taille1 = adjust_length(s+al,16);
> uint8_t *Add=new uint8_t[taille1];
>
> memcpy(Add,ll,s);
> memcpy(Add+s,aa,al);
> memcpy(Pl,mm,ml);
>
> taille2 = adjust_length(ml,16);
>
> memcpy(Au,Add,taille1);
> memcpy(Au+taille1,Pl,taille2);
>
>
> delete ll;
> delete AddAuthData;

This is very nonidiomatic C++. I haven't bothered to find the memory
error in this code, but you should consider rewriting all of it into C++
using std::vector. This will probably get rid of the memory error. For
example, instead of uint8_t *ll=new uint8_t[10]; you do
std::vector<uint8_t> ll(10);

delete ll; is cancelled, the compiler automatically gets rid of ll for
you. Instead of memcpy you either use std::copy or a for loop. etc.

Christian


red floyd

unread,
Jun 7, 2015, 1:50:42 PM6/7/15
to
Or, since it's a fixed size, don't even bother with a vector, either use
a naked array of 10 (uint8_t ll[10]), or a std:array<uint8_t,10> ll;


Barry Schwarz

unread,
Jun 7, 2015, 1:53:32 PM6/7/15
to
On Sun, 7 Jun 2015 08:30:09 -0700 (PDT), ghada glissa
<ghada...@gmail.com> wrote:

>Hi all,
>
>I have a C++ program that I wrote. The code compiles without any error or warning message. But when I execute it, I get
>
>*** glibc detected ***: corrupted double-linked list: 0x000000000564d6f0 ***
>
>Source code:
>
>void Prog:: input_transfo(uint8_t al,uint8_t ml,uint8_t* aa, uint8_t* mm,
> uint8_t* Pl, uint8_t* Au){
>
> uint8_t s=0;
> uint8_t *ll=new uint8_t[10];
>
> input(al,s,ll);

What data, if any, does this function put in ll? Does it magically
change s?

> taille1 = adjust_length(s+al,16);

What is the value of al? What does the function do?

> uint8_t *Add=new uint8_t[taille1];
>
> memcpy(Add,ll,s);

What do you expect memcpy to do since s is 0?

> memcpy(Add+s,aa,al);
> memcpy(Pl,mm,ml);
>
> taille2 = adjust_length(ml,16);

What does this function do?

> memcpy(Au,Add,taille1);
> memcpy(Au+taille1,Pl,taille2);
>
>
> delete ll;
> delete AddAuthData;

What is AddAuthData? Do it point to allocated memory? Where do you
delete the memory allocated to Add?

> }
>
>void Prog:: auth(uint8_t authlen,uint8_t al,uint8_t ml,uint8_t *n,uint8_t*a,uint8_t *ms,uint8_t *k, uint8_t *MAC){

Parameters authlen, n, k, and MAC appear to be unused in the function?

> uint8_t *Pl=new uint8_t[taille2];
> uint8_t *Au=new uint8_t[taille1+taille2];
>
> input_transfo(al,ml,a,ms,Pl,Au);
>
>
> delete PlainData;
> delete AuData;

What are PlainData and AuData? Do they point to allocated memory?
Where do you delete the memory allocated to Pl and Au?

> }
>
>taille1 et taille2 are two globale variables
>I got this error when i use the second function which uses the first function.
>
>any help please??

Show us your real code, the type of each global variable, and the
values of both global variables and function arguments. Tell us what
the uncoded called functions do. Invest in a little horizontal white
space to make your code readable.

--
Remove del for email

Louis Krupp

unread,
Jun 7, 2015, 1:56:22 PM6/7/15
to
On Sun, 7 Jun 2015 08:30:09 -0700 (PDT), ghada glissa
<ghada...@gmail.com> wrote:

>Hi all,
>
>I have a C++ program that I wrote. The code compiles without any error or warning message. But when I execute it, I get
>
>*** glibc detected ***: corrupted double-linked list: 0x000000000564d6f0 ***
>
<snip>

You're probably doing something like this:

char *dest = new char[40];
memcpy(dest, src, 44);

When you allocate a block of memory from the heap, the system adds
some information of its own before and after your allocation; this
is how it keeps track of what heap memory is in use and what's free.
When you overrun the end of your allocation, you destroy some of that
information; at some point, the system detects that and stops your
program.

valgrind might help you debug this.

Louis

Mr Flibble

unread,
Jun 7, 2015, 5:55:17 PM6/7/15
to
As others have suggested you should be using std::vector or std::array.
For future reference you must always delete[] what you new[], i.e.:

char* a = new char[42];
delete[] a;

/Flibble

0 new messages