I have some simple program written in C (for Linux, xorg desktop).
What it does is when it runs, it saves content of root window image (currently active background wallpaper) to a file. This program runs just fine, it is 132 lines of code.
I need to include this functionality to my other software, so I copied the functions, include declarations, etc, and it works just fine in my own application. But only if I run it 5 times or 6 times, then it stops working and reports some error (bad Drawable). Once this error happens, it fails to run until I quit the graphical X11 desktop. When I startx again and run my compiled program again, it works just fine about 6x and then there is again the error.
I am amateur C programmer so I do not know how to debug the code to find out whats wrong. I need you to debug my conde and attempt to fix my issue, or at least identify root cause for it.
Source files attached.
Instructions:
getbg.c: if I compile and run only this, it works 100 times, no problem
launcher.c: if I compile and run this, it works only about 6 times, then error, and getbg.c stops working too, after the error is encountered in launcher.c
In order for the launcher to work properly, you will need a config file, which is generated from your desktop applications list. genconf script is attached, run it as this:
./genconf > ./conf