Skip to content

Commit 46120ab

Browse files
Merge pull request #503 from tass-belgium/dev_master_memleak
Resolved memory leak
2 parents e25d3b7 + 83527c6 commit 46120ab

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

modules/pico_ethernet.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static int pico_ethernet_ipv6_dst(struct pico_frame *f, struct pico_eth *const d
295295

296296
/* Ethernet send, first attempt: try our own address.
297297
* Returns 0 if the packet is not for us.
298-
* Returns 1 if the packet is cloned to our own receive queue, so the caller can discard the original frame.
298+
* Returns 1 if the packet is cloned to our own receive queue and the original frame is dicarded.
299299
* */
300300
static int32_t pico_ethsend_local(struct pico_frame *f, struct pico_eth_hdr *hdr)
301301
{
@@ -308,7 +308,9 @@ static int32_t pico_ethsend_local(struct pico_frame *f, struct pico_eth_hdr *hdr
308308
dbg("sending out packet destined for our own mac\n");
309309
if (pico_ethernet_receive(clone) < 0) {
310310
dbg("pico_ethernet_receive() failed\n");
311+
return 0;
311312
}
313+
pico_frame_discard(f);
312314
return 1;
313315
}
314316

@@ -317,13 +319,12 @@ static int32_t pico_ethsend_local(struct pico_frame *f, struct pico_eth_hdr *hdr
317319

318320
/* Ethernet send, second attempt: try bcast.
319321
* Returns 0 if the packet is not bcast, so it will be handled somewhere else.
320-
* Returns 1 if the packet is handled by the pico_device_broadcast() function, so it can be discarded.
322+
* Returns 1 if the packet is handled by the pico_device_broadcast() function and is discarded.
321323
* */
322324
static int32_t pico_ethsend_bcast(struct pico_frame *f)
323325
{
324326
if (IS_LIMITED_BCAST(f)) {
325-
(void)pico_device_broadcast(f); /* We can discard broadcast even if it's not sent. */
326-
return 1;
327+
return (pico_device_broadcast(f) > 0); // Return 1 on success, ret > 0
327328
}
328329

329330
return 0;

stack/pico_device.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ int32_t pico_device_broadcast(struct pico_frame *f)
450450
{
451451
struct pico_tree_node *index;
452452
int32_t ret = -1;
453+
int sent = 0;
453454

454455
pico_tree_foreach(index, &Device_tree)
455456
{
@@ -462,14 +463,29 @@ int32_t pico_device_broadcast(struct pico_frame *f)
462463
break;
463464

464465
copy->dev = dev;
465-
copy->dev->send(copy->dev, copy->start, (int)copy->len);
466+
ret = copy->dev->send(copy->dev, copy->start, (int)copy->len);
467+
/* FIXME: If a device driver returns zero (which means the device
468+
* driver is currently busy) there is no means to retry the
469+
* broadcast operation later. */
466470
pico_frame_discard(copy);
467471
}
468472
else
469473
{
470474
ret = f->dev->send(f->dev, f->start, (int)f->len);
475+
/* FIXME: If a device driver returns zero (which means the device
476+
* driver is currently busy) there is no means to retry the
477+
* broadcast operation later. */
478+
}
479+
480+
/* FIXME: If at least one device driver was able to sent the frame on
481+
* the wire, the broadcast operation will be considered successful. */
482+
if (ret > 0) {
483+
sent = 1;
471484
}
472485
}
486+
487+
ret = sent ? f->len : -1;
488+
pico_frame_discard(f);
473489
return ret;
474490
}
475491

0 commit comments

Comments
 (0)