Skip to content

Commit b360a71

Browse files
committed
oops, forgot to free() my mallocs
1 parent 96edce4 commit b360a71

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

fw/v24/src/vcp.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ bool VCPWriteDebug1(const char *text)
237237
// Allocate the array
238238
uint8_t *msg = malloc((len + 3) * sizeof *msg);
239239

240+
// Make sure we alloc'd
241+
if (!msg)
242+
{
243+
return false;
244+
}
245+
240246
// Populate header
241247
msg[0] = DVM_FRAME_START;
242248
msg[1] = len + 3;
@@ -246,7 +252,13 @@ bool VCPWriteDebug1(const char *text)
246252
memcpy(msg + 3, text, len);
247253

248254
// Send
249-
return VCPWrite(msg, len + 3);
255+
bool ret = VCPWrite(msg, len + 3);
256+
257+
// Free
258+
free(msg);
259+
260+
// Return
261+
return ret;
250262
}
251263

252264
/**
@@ -271,6 +283,12 @@ bool VCPWriteDebug2(const char *text, int16_t n1)
271283
// Allocate the array (+3 for header, +2 for int)
272284
uint8_t *msg = malloc((len + 5) * sizeof *msg);
273285

286+
// Make sure we alloc'd
287+
if (!msg)
288+
{
289+
return false;
290+
}
291+
274292
// Populate header
275293
msg[0] = DVM_FRAME_START;
276294
msg[1] = len + 5;
@@ -284,7 +302,13 @@ bool VCPWriteDebug2(const char *text, int16_t n1)
284302
msg[len+4] = n1 & 0xFF;
285303

286304
// Send
287-
return VCPWrite(msg, len + 5);
305+
bool ret = VCPWrite(msg, len + 5);
306+
307+
// Free
308+
free(msg);
309+
310+
// Return
311+
return ret;
288312
}
289313

290314
/**
@@ -310,6 +334,12 @@ bool VCPWriteDebug3(const char *text, int16_t n1, int16_t n2)
310334
// Allocate the array (+3 for header, +4 for 2 int)
311335
uint8_t *msg = malloc((len + 7) * sizeof *msg);
312336

337+
// Make sure we alloc'd
338+
if (!msg)
339+
{
340+
return false;
341+
}
342+
313343
// Populate header
314344
msg[0] = DVM_FRAME_START;
315345
msg[1] = len + 7;
@@ -325,7 +355,13 @@ bool VCPWriteDebug3(const char *text, int16_t n1, int16_t n2)
325355
msg[len+6] = n2 & 0xFF;
326356

327357
// Send
328-
return VCPWrite(msg, len + 7);
358+
bool ret = VCPWrite(msg, len + 7);
359+
360+
// Free
361+
free(msg);
362+
363+
// Return
364+
return ret;
329365
}
330366

331367
/**
@@ -352,6 +388,12 @@ bool VCPWriteDebug4(const char *text, int16_t n1, int16_t n2, int16_t n3)
352388
// Allocate the array (+3 for header, +6 for 3 int)
353389
uint8_t *msg = malloc((len + 9) * sizeof *msg);
354390

391+
// Make sure we alloc'd
392+
if (!msg)
393+
{
394+
return false;
395+
}
396+
355397
// Populate header
356398
msg[0] = DVM_FRAME_START;
357399
msg[1] = len + 9;
@@ -369,7 +411,13 @@ bool VCPWriteDebug4(const char *text, int16_t n1, int16_t n2, int16_t n3)
369411
msg[len+8] = n3 & 0xFF;
370412

371413
// Send
372-
return VCPWrite(msg, len + 9);
414+
bool ret = VCPWrite(msg, len + 9);
415+
416+
// Free
417+
free(msg);
418+
419+
// Return
420+
return ret;
373421
}
374422

375423
/**

0 commit comments

Comments
 (0)