Very well put, Antonio Sir.

On 2019-05-27 at 8:10 AM, Antonio Scuri <[email protected]> wrote:
  The only possibility for a leak there if there is an infinite loop in the
"for". The "for" is ended only when "return" is called right after free. 


  If you can show me an actual situation where there is a leak, then we will
try to fix it. But adding a free after the "for" is not a fix.



Best,
Scuri




Em seg, 27 de mai de 2019 às 08:42, Ranier VF <[email protected]>
escreveu:

Hi Scuri,
Acccording to Coverity this is a real bug:

static void iAttribParse(Ihandle *ih, const char* str)
1463{
1464  char env_buffer[256];
1465  char* name=NULL;
1466  char* value=NULL;
1467  char state = 'a';               /* get attribute */
1468  int end = 0;
1469
1470  env_str = str;
1471
    1. Condition true, taking true branch.
    7. Condition true, taking true branch.
    15. Condition true, taking true branch.
1472  for (;;)
1473  {
    2. Switch case value 8.
    8. Switch case value 5.
    16. Switch case value 5.
1474    switch (iAttribToken(env_buffer))
1475    {
    CID 210525: Missing break in switch (MISSING_BREAK) [select issue]
1476    case IUPLEX_TK_END:           /* same as IUPLEX_TK_COMMA */
1477      end = 1;
1478    case IUPLEX_TK_COMMA:
    3. Condition name, taking false branch.
1479      if (name)
1480      {
    CID 210685: Explicit null dereferenced (FORWARD_NULL) [select issue]
1481        IupStoreAttribute(ih, name, value);
1482        free(name);
1483      }
    4. Condition end, taking false branch.
1484      if (end)
1485        return;
1486      name = value = NULL;
1487      state = 'a';
    5. Breaking from switch.
1488      break;
1489
1490    case IUPLEX_TK_SET:
1491      state = 'v';                /* get value */
1492      break;
1493
1494    case IUPLEX_TK_NAME:
    9. Condition state == 97, taking true branch.
    17. Condition state == 97, taking true branch.
1495      if (state == 'a')
    10. alloc_fn: Storage is returned from allocation function iupStrDup.
[show details]
    11. var_assign: Assigning: name = storage returned from
iupStrDup(env_buffer).
    12. Falling through to end of if statement.
    CID 210676 (#1 of 1): Resource leak (RESOURCE_LEAK)18. overwrite_var:
Overwriting name in name = iupStrDup(env_buffer) leaks the storage that name
points to.
1496        name = iupStrDup(env_buffer);
1497      else
1498        value = env_buffer;
    13. Breaking from switch.
1499      break;
1500    }
    6. Jumping back to the beginning of the loop.
    14. Jumping back to the beginning of the loop.
1501  }
1502}

Following the "conditions", that can actually occur, var name leaks pointer.
IHMO I really believe fix this.

Best regards,
Ranier Vilela
________________________________________
De: Antonio Scuri <[email protected]>
Enviado: domingo, 26 de maio de 2019 22:08
Para: IUP discussion list.
Assunto: Re: [Iup-users] CID 210676 (#1 of 1): Resource leak (RESOURCE_LEAK)

The code you added is an unreachable code. The "for" never ends normally, only
in the return.

Em sáb, 25 de mai de 2019 às 08:28, Ranier VF
<[email protected]<mailto:[email protected]>> escreveu:
Hi,
Fix RESOURCE_LEAK at iup_attrib.c

--- ..\..\a\src\iup_attrib.c    Sat Jan 26 16:02:13 2019
+++ iup_attrib.c        Sat May 25 08:25:17 2019
@@ -1499,6 +1499,11 @@
       break;
     }
   }
+  if (name)
+  {
+     IupStoreAttribute(ih, name, value);
+     free(name);
+  }
  }

  Ihandle* IupSetAttributes(Ihandle *ih, const char* str)

Best regards.
Ranier Vilela_______________________________________________
Iup-users mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/iup-users


_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users
_______________________________________________
Iup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to