Skip to content

Commit bfdf2b5

Browse files
committed
fix leak; protect against malloc() fail
1 parent 6fcdd76 commit bfdf2b5

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

main/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ int target_in_irq(void) {
2424

2525
void flush_dmesg(void) {
2626
char *dmesgCopy = malloc(sizeof(codalLogStore));
27+
if (!dmesgCopy)
28+
return;
2729

2830
uint32_t len;
2931

main/rx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ static int jd_rx_frame_received_core(jd_frame_t *frame, int is_loop) {
1414
return 0;
1515

1616
jd_frame_t *copy = malloc(JD_FRAME_SIZE(frame));
17+
if (!copy)
18+
return -1;
19+
1720
memcpy(copy, frame, JD_FRAME_SIZE(frame));
1821

1922
if (!is_loop)

main/usb.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ static void hf2_send_buffer(uint8_t flag, const void *data, unsigned size, uint3
109109
size += 4;
110110

111111
BufferEntry *ent = (BufferEntry *)malloc(sizeof(BufferEntry) + size);
112+
if (!ent)
113+
return;
114+
112115
ent->size = size;
113116
ent->flag = flag;
114117
uint8_t *dst = ent->data;
@@ -121,8 +124,10 @@ static void hf2_send_buffer(uint8_t flag, const void *data, unsigned size, uint3
121124

122125
memcpy(dst, data, size);
123126

124-
if (worker_run(fg_worker, send_buffer_core, ent) != 0)
127+
if (worker_run(fg_worker, send_buffer_core, ent) != 0) {
125128
OVF_ERROR("HF2 queue full");
129+
free(ent);
130+
}
126131
}
127132

128133
int hf2_send_event(uint32_t evId, const void *data, int size) {

0 commit comments

Comments
 (0)