ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
fails to execute, with the following error message:
a.out: malloc.c:2842: mremap_chunk: Assertion `((size + offset) & (_rtld_global_ro._dl_pagesize - 1)) == 0' failed.
I am clueless as to what is happening. It makes no sense to me why that line fails after the line two lines previously, which is essentially identical, fails.
fails to execute, with the following error message:
a.out: malloc.c:2842: mremap_chunk: Assertion `((size + offset) & (_rtld_global_ro._dl_pagesize - 1)) == 0' failed.
I am clueless as to what is happening. It makes no sense to me why that line fails after the line two lines previously, which is essentially identical, fails.
There is some seriously ugly stuff in there. It's a hard to read, incomplete code segment which makes it hard to help with but in ...
int *type=NULL, *value = NULL, n=0, i;
for(i = 0; i< 5; i++){
type = realloc(type, sizeof(int) * ++n);
value = realloc(value, sizeof(int) *n);
}
type = realloc(type, sizeof(int) * ++n);
printf("you are here (1) n=%d\n", n);
value = realloc(value, sizeof(int) *n);
printf("you are here (2) n=%d\n", n);
"you are here (1)" reports that n = 6
The following line crashes the program with the error message:
a.out: malloc.c:2842: mremap_chunk: Assertion `((size + offset) & (_rtld_global_ro._dl_pagesize - 1)) == 0' failed.
I.e. the program does not reach "you are here (2)"
I agree that to be rigorous, I should probably use:
Yes, as NemenTeve says, the problem lies elsewhere. The error message is an assertion failure within the malloc that is called by realloc, which indicates that something has already corrupted memory at that point. One way forward is to use valgrind to track down where the corruption is actually happening.
I did a test with an included malloc(103) (i.e (sizeof(char*) + 103) subtracted from the heap for each loop) and looped up to 20000 iterations. If realloc was going to crap out due to crossing a page boundary, it should have shown up with that test. It ran fine.
I havent'f found the error in my program yet, but apparently the realloc isn't the problem.
I am marking this thread as "solved" Thaks one and all for your support.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.