Skip to content

Commit 03351e0

Browse files
committed
wiimote: correctly free sockets & structs
1 parent 959871c commit 03351e0

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎wiiuse/io_wii.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ static s32 __wiiuse_disconnected(void *arg,struct bte_pcb *pcb,u8 err)
6464

6565
bte_free(wml->sock);
6666
wml->sock = NULL;
67+
if(wm->sock==wml->sock)
68+
wm->sock = NULL;
6769
return ERR_OK;
6870
}
6971

‎wiiuse/wiiuse.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ void wiiuse_cleanup(struct wiimote_t **wm, int wiimotes)
6868
wm[i]->queue_buffer = NULL;
6969
}
7070

71+
//should normally have been free'd by other code, but just in case it isnt
72+
//to remove?
7173
if (wm[i]->sock) {
7274
bte_free(wm[i]->sock);
7375
wm[i]->sock = NULL;
@@ -77,6 +79,9 @@ void wiiuse_cleanup(struct wiimote_t **wm, int wiimotes)
7779
}
7880
}
7981

82+
//clear internal pointer too
83+
if (wm == __wm)
84+
__wm = NULL;
8085
free(wm);
8186
}
8287

@@ -98,8 +103,10 @@ struct wiimote_t** wiiuse_init(int wiimotes, wii_event_cb event_cb) {
98103
}
99104

100105
for (i = 0; i < wiimotes; ++i) {
101-
if(!__wm[i])
106+
if (!__wm[i]) {
102107
__wm[i] = malloc(sizeof(struct wiimote_t));
108+
if (!__wm[i]) return NULL; // Lets try to avoid crashing if OOM
109+
}
103110

104111
memset(__wm[i], 0, sizeof(struct wiimote_t));
105112
__wm[i]->unid = i;

0 commit comments

Comments
 (0)