Permalink
Browse files

freenect: avoid leaking the context when fnusb_init() fails

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 <ospite@studenti.unina.it>
  • Loading branch information...
1 parent 6e6015c commit 7205faad0ca6f9bb0a514ab5b1e3bd46f840ba53 @ao2 ao2 committed with zarvox Feb 28, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/core.c
View
@@ -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;
@@ -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)

0 comments on commit 7205faa

Please sign in to comment.