Permalink
Browse files

Fix memory leak on receive path.

receive() attempts to avoid memory management by using a local
variable "notice" as the storage area for the Zephyr notice object.
However, one still needs to call ZFreeNotice on the object at the end,
to free notice->z_packet.
  • Loading branch information...
1 parent 12466a6 commit 2869928ccf031a9936ccf4d3b77750265876bc1a @timabbott timabbott committed Jan 2, 2013
Showing with 9 additions and 6 deletions.
  1. +9 −6 _zephyr.pyx
View
@@ -220,13 +220,16 @@ def receive(block=False):
errno = ZReceiveNotice(&notice, &sender)
__error(errno)
- if ZCheckAuthentication(&notice, &sender) == ZAUTH_YES:
- notice.z_auth = 1
- else:
- notice.z_auth = 0
+ try:
+ if ZCheckAuthentication(&notice, &sender) == ZAUTH_YES:
+ notice.z_auth = 1
+ else:
+ notice.z_auth = 0
- p_notice = ZNotice()
- _ZNotice_c2p(&notice, p_notice)
+ p_notice = ZNotice()
+ _ZNotice_c2p(&notice, p_notice)
+ finally:
+ ZFreeNotice(&notice)
return p_notice
def sender():

0 comments on commit 2869928

Please sign in to comment.