lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] [bug #21077] lwip_stats.mem.used is inaccurate, sometimes n


From: Mike Kleshov
Subject: [lwip-devel] [bug #21077] lwip_stats.mem.used is inaccurate, sometimes negative
Date: Fri, 14 Sep 2007 20:33:57 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.5) Gecko/20070713 Firefox/2.0.0.5

Follow-up Comment #1, bug #21077 (project lwip):

Having spent some time analyzing the code in mem.c, I think I found where the
problem comes from.

In the function mem_malloc(), lwip_stats.mem.used is updated as follows (line
470):
lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM);

But a few lines before that (see line 459), a block is reused whose size is
larger than the requested size. Note the comment:
* also can't move mem->next directly behind mem, since mem->next
* will always be used at this point!

Taking this into account, in the mentioned special case lwip_stats.mem.used
should be updated using mem->next:
lwip_stats.mem.used += mem->next - ((u8_t *)mem - ram); /* suggested fix */

By the way, mem->next is used to update it in mem_free():
lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram);

A quick test confirms that the fix works, lwip_stats.mem.used seems to behave
normal.
Can anyone comment on this? I can commit the changes if there are no
objections.

- Mike

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?21077>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/





reply via email to

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