Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8362884

[GCC static analyzer] unix NetworkInterface.c addif leak in early returns

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 25, 26
    • core-libs
    • None
    • generic
    • generic

      When building with the gcc static analyzer (-fanalyzer) the following small leak is reported. It basically says that in CHECKED_MALLOC3 in line 998 an early return can potentially happen; but in this (rare) case the allocated memory from earlier CHECKED_MALLOC3' (line 949) is not freed.

      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c: In function 'addif':
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:65:13: warning: leak of 'addrP' [CWE-401] [-Wanalyzer-malloc-leak]
         65 | return ifs; /* return untouched list */ \
            | ^~~~~~
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:998:10: note: in expansion of macro 'CHECKED_MALLOC3'
        998 | CHECKED_MALLOC3(currif, netif *, sizeof(netif) + IFNAMESIZE);
            | ^~~~~~~~~~~~~~~
        'addif': event 1
          |
          | 62 | _pointer = (_type)malloc(_size); \
          | | ^~~~~~~~~~~~~
          | | |
          | | (1) allocated here
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:949:5: note: in expansion of macro 'CHECKED_MALLOC3'
          | 949 | CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr) + 2 * addr_size);
          | | ^~~~~~~~~~~~~~~
          |
        'addif': event 2
          |
          | 63 | if (_pointer == NULL) { \
          | | ^
          | | |
          | | (2) assuming 'addrP' is non-NULL
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:949:5: note: in expansion of macro 'CHECKED_MALLOC3'
          | 949 | CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr) + 2 * addr_size);
          | | ^~~~~~~~~~~~~~~
          |
        'addif': event 3
          |
          | 63 | if (_pointer == NULL) { \
          | | ^
          | | |
          | | (3) following 'false' branch (when 'addrP' is non-NULL)...
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:949:5: note: in expansion of macro 'CHECKED_MALLOC3'
          | 949 | CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr) + 2 * addr_size);
          | | ^~~~~~~~~~~~~~~
          |
        'addif': event 4
          |
          | 61 | do { \
          | | ^
          | | |
          | | (4) ...to here
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:949:5: note: in expansion of macro 'CHECKED_MALLOC3'
          | 949 | CHECKED_MALLOC3(addrP, netaddr *, sizeof(netaddr) + 2 * addr_size);
          | | ^~~~~~~~~~~~~~~
          |
        'addif': events 5-8
          |
          | 958 | if (family == AF_INET && ifr_broadaddrP != NULL) {
          | | ^
          | | |
          | | (5) following 'true' branch...
          | 959 | addrP->brdcast = (struct sockaddr *)
          | | ~~~~~
          | | |
          | | (6) ...to here
          |......
          | 967 | name_colonP = strchr(name, ':');
          | | ~~~~~~~~~~~~~~~~~
          | | |
          | | (7) when 'strchr' returns NULL
          | 968 | if (name_colonP != NULL) {
          | | ~
          | | |
          | | (8) following 'false' branch (when 'name_colonP' is NULL)...
          |
        'addif': event 9
          |
          |cc1:
          | (9): ...to here
          |
        'addif': events 10-12
          |
          | 989 | while (currif != NULL) {
          | | ^
          | | |
          | | (10) following 'false' branch (when 'currif' is NULL)...
          |......
          | 997 | if (currif == NULL) {
          | | ~~ ~
          | | | |
          | | | (12) following 'true' branch (when 'currif' is NULL)...
          | | (11) ...to here
          |
        'addif': event 13
          |
          | 61 | do { \
          | | ^~
          | | |
          | | (13) ...to here
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:998:10: note: in expansion of macro 'CHECKED_MALLOC3'
          | 998 | CHECKED_MALLOC3(currif, netif *, sizeof(netif) + IFNAMESIZE);
          | | ^~~~~~~~~~~~~~~
          |
        'addif': event 14
          |
          | 63 | if (_pointer == NULL) { \
          | | ^
          | | |
          | | (14) following 'true' branch (when 'currif' is NULL)...
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:998:10: note: in expansion of macro 'CHECKED_MALLOC3'
          | 998 | CHECKED_MALLOC3(currif, netif *, sizeof(netif) + IFNAMESIZE);
          | | ^~~~~~~~~~~~~~~
          |
        'addif': event 15
          |
          | 64 | JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed"); \
          | | ^~~~~~~~~~~~~~~~~~~~~~~~~
          | | |
          | | (15) ...to here
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:998:10: note: in expansion of macro 'CHECKED_MALLOC3'
          | 998 | CHECKED_MALLOC3(currif, netif *, sizeof(netif) + IFNAMESIZE);
          | | ^~~~~~~~~~~~~~~
          |
        'addif': event 16
          |
          | 65 | return ifs; /* return untouched list */ \
          | | ^~~~~~
          | | |
          | | (16) 'addrP' leaks here; was allocated at (1)
      /jdk/src/java.base/unix/native/libnet/NetworkInterface.c:998:10: note: in expansion of macro 'CHECKED_MALLOC3'
          | 998 | CHECKED_MALLOC3(currif, netif *, sizeof(netif) + IFNAMESIZE);
          | | ^~~~~~~~~~~~~~~



            mbaesken Matthias Baesken
            mbaesken Matthias Baesken
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: