Skip to content

Commit

Permalink
Resolved memory leak
Browse files Browse the repository at this point in the history
Cherry-picked 81cde92 from development.
  • Loading branch information
Jelle De Vleeschouwer committed Oct 22, 2019
1 parent e25d3b7 commit 83527c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
9 changes: 5 additions & 4 deletions modules/pico_ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static int pico_ethernet_ipv6_dst(struct pico_frame *f, struct pico_eth *const d

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

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

/* Ethernet send, second attempt: try bcast.
* Returns 0 if the packet is not bcast, so it will be handled somewhere else.
* Returns 1 if the packet is handled by the pico_device_broadcast() function, so it can be discarded.
* Returns 1 if the packet is handled by the pico_device_broadcast() function and is discarded.
* */
static int32_t pico_ethsend_bcast(struct pico_frame *f)
{
if (IS_LIMITED_BCAST(f)) {
(void)pico_device_broadcast(f); /* We can discard broadcast even if it's not sent. */
return 1;
return (pico_device_broadcast(f) > 0); // Return 1 on success, ret > 0
}

return 0;
Expand Down
18 changes: 17 additions & 1 deletion stack/pico_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ int32_t pico_device_broadcast(struct pico_frame *f)
{
struct pico_tree_node *index;
int32_t ret = -1;
int sent = 0;

pico_tree_foreach(index, &Device_tree)
{
Expand All @@ -462,14 +463,29 @@ int32_t pico_device_broadcast(struct pico_frame *f)
break;

copy->dev = dev;
copy->dev->send(copy->dev, copy->start, (int)copy->len);
ret = copy->dev->send(copy->dev, copy->start, (int)copy->len);
/* FIXME: If a device driver returns zero (which means the device
* driver is currently busy) there is no means to retry the
* broadcast operation later. */
pico_frame_discard(copy);
}
else
{
ret = f->dev->send(f->dev, f->start, (int)f->len);
/* FIXME: If a device driver returns zero (which means the device
* driver is currently busy) there is no means to retry the
* broadcast operation later. */
}

/* FIXME: If at least one device driver was able to sent the frame on
* the wire, the broadcast operation will be considered successful. */
if (ret > 0) {
sent = 1;
}
}

ret = sent ? f->len : -1;
pico_frame_discard(f);
return ret;
}

Expand Down

0 comments on commit 83527c6

Please sign in to comment.