Skip to content

Commit 56bda29

Browse files
committed
Correctly free socket on wiimote disconnect
1 parent 4d5665a commit 56bda29

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

wiiuse/io_wii.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ static s32 __wiiuse_disconnected(void *arg,struct bte_pcb *pcb,u8 err)
5353

5454
if(wm->event_cb) wm->event_cb(wm,WIIUSE_DISCONNECT);
5555

56-
bte_free(wml->sock);
57-
wml->sock = NULL;
58-
5956
wml->wm = NULL;
6057
return ERR_OK;
6158
}
@@ -204,7 +201,6 @@ void wiiuse_disconnect(struct wiimote_t *wm)
204201

205202
WIIMOTE_DISABLE_STATE(wm,WIIMOTE_STATE_CONNECTED);
206203
bte_disconnect(wm->sock);
207-
wm->sock = NULL;
208204
}
209205

210206
void wiiuse_sensorbar_enable(int enable)

wiiuse/wpad.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ distribution.
5454
#define EVENTQUEUE_LENGTH 16
5555

5656
#define DISCONNECT_TIMEOUT 0x08 /* HCI_CONN_TIMEOUT */
57+
#define DISCONNECT_USER_ENDED 0x13 /* HCI_OTHER_END_TERMINATED_CONN_USER_ENDED */
5758
#define DISCONNECT_BATTERY_DIED 0x14 /* HCI_OTHER_END_TERMINATED_CONN_LOW_RESOURCES */
5859
#define DISCONNECT_POWER_OFF 0x15 /* HCI_OTHER_END_TERMINATED_CONN_ABOUT_TO_POWER_OFF */
5960
#define DISCONNECT_IDLE_TIMEOUT 0x16 /* HCI_CONN_TERMINATED_BY_LOCAL_HOST */
@@ -793,10 +794,15 @@ void __wpad_disconnectCB(struct bd_addr *pad_addr, u8 reason)
793794
case DISCONNECT_TIMEOUT:
794795
// Controller stopped responding for an unknown reason
795796
break;
797+
case DISCONNECT_USER_ENDED:
798+
printf("WPAD User Disconnect (what?)\n");
799+
break;
796800
default:
797801
printf("WPAD Unknown Disconnect Reason(%d)\n", reason);
798802
break;
799803
}
804+
bte_free(__wpads_listen[i].sock);
805+
__wpads_listen[i].sock = NULL;
800806
__wpads_used &= ~(0x01<<i);
801807
break;
802808
}
@@ -1115,6 +1121,8 @@ s32 WPAD_WipeSavedControllers(void)
11151121
for(i=0;i<WPAD_MAX_DEVICES;i++) {
11161122
__wpad_disconnect(&__wpdcb[i]);
11171123
memset(__wpads_listen[i].name, 0, sizeof(__wpads_listen[i].name));
1124+
bte_free(__wpads_listen[i].sock);
1125+
__wpads_listen[i].sock = NULL;
11181126
}
11191127
__wpads_active = 0;
11201128
__wpads_used = 0;

0 commit comments

Comments
 (0)