Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

realloc: invalid next size, detected by glibc [duplicate]

My code:

int args_size = 5;
char** args;

args = (char**) malloc(sizeof(char*) * args_size);

// ...

args = (char**) realloc(args, sizeof(char*) * (args_size += 5));

I want to increase the size by 5.

But I get this error:

*** glibc detected *** ./a.out: realloc(): invalid next size: 0x0000000000a971c0 ***

I know that a temp variable catching realloc is good, but just for simplicity...

like image 617
Sam Avatar asked Apr 07 '13 12:04

Sam


1 Answers

SOLVED

Initially, the size of args is 5 elements. As the program was filling args, it was mistakenly adding 6th element to it and then calling realloc.

That caused the error mentioned in the question.

Problem is solved by eliminating the error, by following the comments of WhozCraig, Jens Gustedt and others...

Thanks to all!

like image 60
Sam Avatar answered Nov 14 '22 17:11

Sam