Skip to content

Commit 7205faa

Browse files
Antonio Ospitezarvox
authored andcommitted
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>
1 parent 6e6015c commit 7205faa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/core.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)
4242
{
43+
int res;
44+
4345
*ctx = (freenect_context*)malloc(sizeof(freenect_context));
4446
if (!ctx)
4547
return -1;
@@ -52,7 +54,12 @@ FREENECTAPI int freenect_init(freenect_context **ctx, freenect_usb_context *usb_
5254
| FREENECT_DEVICE_AUDIO
5355
#endif
5456
);
55-
return fnusb_init(&(*ctx)->usb, usb_ctx);
57+
res = fnusb_init(&(*ctx)->usb, usb_ctx);
58+
if (res < 0) {
59+
free(*ctx);
60+
*ctx = NULL;
61+
}
62+
return res;
5663
}
5764

5865
FREENECTAPI int freenect_shutdown(freenect_context *ctx)

0 commit comments

Comments
 (0)