Skip to content

Commit 558bf8d

Browse files
committed
wpad: check for out of memory error
1 parent 7b2fac7 commit 558bf8d

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

wiiuse/io_wii.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,18 @@ void wiiuse_sensorbar_enable(int enable)
265265
__wiiuse_sensorbar_enable(enable);
266266
}
267267

268-
void wiiuse_init_cmd_queue(struct wiimote_t *wm)
268+
int wiiuse_init_cmd_queue(struct wiimote_t *wm)
269269
{
270270
u32 size;
271271

272272
if (!__queue_buffer[wm->unid]) {
273273
size = (MAX_COMMANDS*sizeof(struct cmd_blk_t));
274274
__queue_buffer[wm->unid] = __lwp_wkspace_allocate(size);
275-
if(!__queue_buffer[wm->unid]) return;
275+
if(!__queue_buffer[wm->unid]) return ERR_MEM;
276276
}
277277

278278
__lwp_queue_initialize(&wm->cmdq,__queue_buffer[wm->unid],MAX_COMMANDS,sizeof(struct cmd_blk_t));
279+
return ERR_OK;
279280
}
280281

281282
int wiiuse_io_write(struct wiimote_t *wm,ubyte *buf,int len)

wiiuse/wiiuse.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ struct wiimote_t** wiiuse_init(int wiimotes, wii_event_cb event_cb) {
8888
__wm[i]->sock = NULL;
8989
__wm[i]->bdaddr = *BD_ADDR_ANY;
9090
__wm[i]->event_cb = event_cb;
91-
wiiuse_init_cmd_queue(__wm[i]);
91+
if (wiiuse_init_cmd_queue(__wm[i])) {
92+
WIIUSE_ERROR("Could not allocate command queue");
93+
return NULL;
94+
}
9295
#elif defined(unix)
9396
__wm[i]->bdaddr = *BDADDR_ANY;
9497
__wm[i]->out_sock = -1;

wiiuse/wiiuse_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ struct op_t
267267
} __attribute__((packed));
268268

269269
/* not part of the api */
270-
void wiiuse_init_cmd_queue(struct wiimote_t *wm);
270+
int wiiuse_init_cmd_queue(struct wiimote_t *wm);
271271
void wiiuse_send_next_command(struct wiimote_t *wm);
272272
int wiiuse_set_report_type(struct wiimote_t* wm,cmd_blk_cb cb);
273273
int wiiuse_sendcmd(struct wiimote_t *wm,ubyte report_type,ubyte *msg,int len,cmd_blk_cb cb);

0 commit comments

Comments
 (0)