[En-Nut-Discussion] Memory leak in UxmlParseStream?

Bernd Walter enut at cicely.de
Mon Dec 14 04:37:10 CET 2009


On Mon, Dec 14, 2009 at 03:23:49AM +0100, Bernd Walter wrote:
> While hunting for lost heap I'd noticed the following code (ethernut-4.8.2):
> 
>                 /* Parse the attributes. */
>                 for (;;) {
>                     if ((tp = UxmlParseTag(tp, tkn, MAX_UXMLTKN_SIZE)) == NULL || *tkn == '>') {
>                         /* End of this tag or error. */
>                         break;
>                     }
>                     if (isalpha(*tkn) && UxmlFilterMatch(tkn, f_attr)) {
>                         size_t len = strlen(tkn) + 1;
>                         char *name = malloc(len);
> 
>                         if (name) {
>                             memcpy(name, tkn, len);
>                             if ((tp = UxmlParseTag(tp, tkn, MAX_UXMLTKN_SIZE)) == NULL || *tkn != '=') {
>                                 break;
>                             }
>                             if ((tp = UxmlParseTag(tp, tkn, MAX_UXMLTKN_SIZE)) == NULL || *tkn == '>') {
>                                 break;
>                             }
>                             UxmlNodeAddAttrib(node, name, tkn);
>                             free(name);
>                         }
>                     }
>                 }
> 
> Inside the for loop the variable name gets memory, but before free'ing
> it there is a chance of breaking out of it.
> This is an error condition, so likely not the reason for my lost memory,
> but still doesn't look Ok.

In the mean time I've found my own _memory_leak_.
Thanks to NUTDEBUG_HEAP I could identify _sbrk as the reason.
Normaly I have 24k free and then if dropped down to 8k.
The cause was an added output printing float - call it once and by by
memory.
I've setup LIB_HEAPSIZE to 2048 Bytes - 16k is too much for 64k RAM.
Are there any expiriences on how small this value can be set?

-- 
B.Walter <bernd at bwct.de> http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.



More information about the En-Nut-Discussion mailing list