Sunday, October 14, 2007

Bug Fix #1

I worked on repelling a program bug for almost a week. Surprisingly, the most time-taking part isn't on how to fix it, but on how to find it. For the purpose, I had to realize the program flow to make sure where the program crashed. Not only c codes but javascript codes are involved in, which make the task a little harder, and even now I don't get the whole picture of the entire program. Thanks to the finding that the bug dwells in a function, I can stop looking into the deeper part of the program.
Here is the simplified problematic segment,

system("rm -f filename.txt");
fp = fopen("filename.txt", "w");
...
fclose(fp);

Got it? The program may crash if it trying to access the file but the file is removed by system(), which fork another process to do removal. And the problem isn't how system() does, but when it does. (The removal process created by system() may executed after fopen() called, and it depends on the os scheculer.)
I replace system() with remove() to remove file.

To look back, I can't stand how stupid that I am by means of how much time was wasted. But I am glad to be free to go ahead.

No comments: