Potentially accessing already freed pointer

Do not access r if chatr_free has been called on it
Merge pull request #14 from alanz/patch-3

Potentially accessing already freed pointer