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.
I have an ESLQ/C program that shows the error on console below during runtime. It is an executable that reads and processes text files by using some user-defined file processing functions. I have tried Valgrind and Splint. Valgrind shows two errors at the line when db connection is established, while Splint shows error like "memory not freed before returned" which i did edit the code to solve it, but... the same glibc error still occurs during runtime. Any idea how to debug and trace such errors?
NOTE:
Although the backtrace shows the similar function name everytime this error happens but the error displayed after "*** glibc detected *** SAM-UPD:" is not the same everytime.
eg.,
-bash-3.2$ *** glibc detected *** SAM-UPD: free(): invalid pointer
-bash-3.2$ *** glibc detected *** SAM-UPD: double free or corruption (!prev): 0x00000
-bash-3.2$ *** glibc detected *** SAM-UPD: corrupted double-linked list: 0x0000000006cfb7a0
Easiest way I've found is to put printf() messages in your code, and move them until you know which line is causing the error (e.g. put one at the start. If you run it, the message should print, and then the error should trigger. Keep moving the printf() through the code until the error comes first, and then you should know which line has the error). You then need to work backwards, and see where else you have freed that pointer.
Obviously, this approach's success will vary with the complexity of your code. If it's too complicated, perhaps try looking at gdb or other such tools.
printf doesn't seem to help much as i cannot simulate this issue consistently and this is an existing program coded according to a framework done internally in the company long long time ago. No one can 100 per cent tell how it works.
Can i debug based on the functions displayed under "Backtrace" ? does "Backtrace" provide relevant and useful information ? How can i debug based on "Backtrace" ?
This has been solved with GDB. It is found that there is a checking on whether a file descriptor is NULL/has a value before fclose() is executed. However, fclose() does not nullify the file descriptor and it results in the same file descriptor being closed for multiple times.Thanks all for the help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.