Fix leaking resource "pid"

pid after being allocated, missed to be freed at many places where return is called.
Applied fix.
Merge pull request #5 from ya1gaurav/patch-5

Fix leaking resource "pid"