Segfault on search when user data for the callback is not given
When no user data is given for the callback of a search query, then there can happen a segfault. I propose a patch. But it is to be noted that:
- If the user does not give a user data parameter, then its callback should not have a parameter for it. But I think it makes sense like that. This is a change in the API, but the users will have their code failing with a nice error telling them there is a parameter too many on their callback.
- Looking at the code, there are lots of memory leaks. This is specially a problem for programs which run as daemon. For instance, the two pointers callback and userdata are not decremented for the GC, and the struct containing the pointers is not deallocated. This patch does not address this problem. You should think of using valgrind to hunt those leaks.
I do not know how to attach a file on github: http://www.valentindavid.com/files/pyspotify-master-segfault_on_search.patch
Thanks a lot for your great work Valentin! I have applied your patch and tested it in my pyspotify branch which I use together with the Mopidy project I am working on. Seems to be solving an annoying problem we had with Mopidy segfaulting while searching. The memory leaks should be fixed some time too, but at least this solves our issues temporarily. You are more than welcome to contribute, if you have the time!
Winjer, hope you can merge this patch in to your master. All credits to Valentin!
After several days of testing, I can confirm that this patch stops Mopidy from segfaulting when playing music and searching simultaneously.
Winjer: Could you merge knutz3n/master?