Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 7205faad0ca6f9bb0a514ab5b1e3bd46f840ba53 1 parent 6e6015c
@ao2 ao2 authored zarvox committed
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/core.c
View
9 src/core.c
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.