Hello,
I read your code and know where is the mistake making your app take buffer overflow.
I'm experienced 9 year in software development in many languages and platform including Python2.7, Network programming, ...
Like java, python was design for auto free memory, but it not work well in many cases. So, we should free memory by manually .
Hire me, i will give you the best.
Thanks,
Binh