Skip to content

Commit

Permalink
freenect: avoid leaking the context when fnusb_init() fails
Browse files Browse the repository at this point in the history
Maybe this is more a theoretical issue than an actual one, I am not sure
in which case fnusb_init() —and hence libusb_init()— is supposed to
fail, but let's handle that once I noticed it.

Signed-off-by: Antonio Ospite <[email protected]>
  • Loading branch information
Antonio Ospite authored and zarvox committed Mar 10, 2012
1 parent 6e6015c commit 7205faa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)
{
int res;

*ctx = (freenect_context*)malloc(sizeof(freenect_context));
if (!ctx)
return -1;
Expand All @@ -52,7 +54,12 @@ FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_
| FREENECT_DEVICE_AUDIO
#endif
);
return fnusb_init(&(*ctx)->usb, usb_ctx);
res = fnusb_init(&(*ctx)->usb, usb_ctx);
if (res < 0) {
free(*ctx);
*ctx = NULL;
}
return res;
}

FREENECTAPI int freenect_shutdown(freenect_context *ctx)
Expand Down

0 comments on commit 7205faa

Please sign in to comment.