Index: main.c =================================================================== RCS file: /cvsroot/bluez/utils/hidd/main.c,v retrieving revision 1.37 diff -u -p -r1.37 main.c --- main.c 8 May 2007 16:38:47 -0000 1.37 +++ main.c 5 Aug 2007 20:13:47 -0000 @@ -460,8 +460,7 @@ static void do_connect(int ctl, bdaddr_t if (err < 0) { perror("Can't get device information"); - close(ctl); - exit(1); + goto exit_ctl; } switch (uuid) { @@ -471,22 +470,19 @@ static void do_connect(int ctl, bdaddr_t case SERIAL_PORT_SVCLASS_ID: if (subclass == 0x40 || !strcmp(name, "Cable Replacement")) { if (epox_presenter(src, dst, channel) < 0) { - close(ctl); - exit(1); + goto exit_ctl; } break; } if (subclass == 0x1f || !strcmp(name, "SPP slave")) { if (jthree_keyboard(src, dst, channel) < 0) { - close(ctl); - exit(1); + goto exit_ctl; } break; } if (subclass == 0x02 || !strcmp(name, "Serial Port")) { if (celluon_keyboard(src, dst, channel) < 0) { - close(ctl); - exit(1); + goto exit_ctl; } break; } @@ -495,8 +491,7 @@ static void do_connect(int ctl, bdaddr_t case HEADSET_SVCLASS_ID: case HANDSFREE_SVCLASS_ID: if (headset_presenter(src, dst, channel) < 0) { - close(ctl); - exit(1); + goto exit_ctl; } break; } @@ -507,28 +502,32 @@ connect: csk = l2cap_connect(src, dst, L2CAP_PSM_HIDP_CTRL); if (csk < 0) { perror("Can't create HID control channel"); - close(ctl); - exit(1); + goto exit_ctl; } isk = l2cap_connect(src, dst, L2CAP_PSM_HIDP_INTR); if (isk < 0) { perror("Can't create HID interrupt channel"); - close(csk); - close(ctl); - exit(1); + goto exit_csk; } err = create_device(ctl, csk, isk, subclass, 1, 1, bootonly, encrypt, timeout); if (err < 0) { fprintf(stderr, "HID create error %d (%s)\n", errno, strerror(errno)); - close(isk); - sleep(1); - close(csk); - close(ctl); - exit(1); + goto exit_isk; } + return; + +exit_isk: + close(isk); + sleep(1); +exit_csk: + close(csk); +exit_ctl: + close(ctl); + + exit(1); } static void do_search(int ctl, bdaddr_t *bdaddr, uint8_t subclass, int fakehid, int bootonly, int encrypt, int timeout) @@ -605,8 +604,7 @@ static void do_kill(int ctl, bdaddr_t *b if (ioctl(ctl, HIDPGETCONNLIST, &cl) < 0) { perror("Can't get connection list"); - close(ctl); - exit(1); + goto fail_ctl; } for (i = 0; i < cl.cnum; i++) { @@ -615,8 +613,7 @@ static void do_kill(int ctl, bdaddr_t *b if (ioctl(ctl, HIDPCONNDEL, &req) < 0) { perror("Can't release connection"); - close(ctl); - exit(1); + goto fail_ctl; } } @@ -626,10 +623,13 @@ static void do_kill(int ctl, bdaddr_t *b if (ioctl(ctl, HIDPCONNDEL, &req) < 0) { perror("Can't release connection"); - close(ctl); - exit(1); + goto fail_ctl; } } + +fail_ctl: + close(ctl); + exit(1); } static void usage(void) @@ -801,23 +801,19 @@ int main(int argc, char *argv[]) case SEARCH: do_search(ctl, &bdaddr, subclass, fakehid, bootonly, encrypt, timeout); - close(ctl); - exit(0); + goto exit_ctl; case CONNECT: do_connect(ctl, &bdaddr, &dev, subclass, fakehid, bootonly, encrypt, timeout); - close(ctl); - exit(0); + goto exit_ctl; case KILL: do_kill(ctl, &dev, flags); - close(ctl); - exit(0); + goto exit_ctl; default: do_show(ctl); - close(ctl); - exit(0); + goto exit_ctl; } if (detach) { @@ -854,6 +850,7 @@ int main(int argc, char *argv[]) close(csk); close(isk); +exit_ctl: close(ctl); return 0;