[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Resource Leak in TCP packet handling in grub, trivial patch

From: Manfred Härtel
Subject: Resource Leak in TCP packet handling in grub, trivial patch
Date: Tue, 17 Sep 2019 20:12:46 +0200
User-agent: Roundcube Webmail/0.7.2

I wrote a grub module which uses the TCP communication functions included in grub for educating myself. :-)

During stress tests I recognized a resource leak. Naturally, I suspected my program first, but could not find a reason why this would happen.

Then I got the feeling that the problem has something to do with the list of unacked outgoing packets in grub, it seems as if some of them do not get unallocated from memory. I also recognized that the unacked queue for a certain socket never exceeds the size of 2 packets, even if it should actually.

While looking through the source code of tcp.c, I think I found the problem and made a trivial patch:

--- tcp.c.orig  2019-09-17 16:38:07.357705163 +0200
+++ tcp.c       2019-09-17 19:41:33.079264637 +0200
@@ -218,7 +218,10 @@
       if (!socket->unack_last)
        socket->unack_first = socket->unack_last = unack;
+      {
        socket->unack_last->next = unack;
+       socket->unack_last = unack;
+      }

   err = grub_net_send_ip_packet (socket->inf, &(socket->out_nla),

Without my patch, a new packet is inserted in the link list after socket->unack_last, but socket->unack_last does not change, so when another unacked packet comes it is prepended to the same packet in the list as before, so the packet we inserted before is not in the linked list anymore, and so never gets unallocated.

The patch seems to solve my problem and I did not recognize any side effects.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]