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...
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With