minor memory leak detected by cppcheck in agent/src/os/linux/symtab.c

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 9
    • Affects Version/s: 7
    • Component/s: hotspot
    • None
    • svc
    • b02
    • generic
    • generic

      Running cppcheck against hotspot sources found a memory leak:

      [SOURCE:LINE] ERROR DETAIL
      [./agent/src/os/linux/symtab.c:218]: (error) Memory leak: debug_pathname

      We neglect to free debug_pathname in the first case of error return:

        char *debug_pathname = malloc(strlen(debug_filename)
                                      + strlen(name)
                                      + strlen(".debug/")
                                      + strlen(debug_file_directory)
                                      + 2);
        strcpy(debug_pathname, name);
        char *last_slash = strrchr(debug_pathname, '/');
      ! if (last_slash == NULL) {
      + free(debug_pathname); // need to free here
          return -1;
      + }

        /* Look in the same directory as the object. */
        strcpy(last_slash+1, debug_filename);

        debug_fd = open_debug_file(debug_pathname, crc);
        if (debug_fd >= 0) {
          free(debug_pathname);
          return debug_fd;
        }
        ...

            Assignee:
            Dmitriy Samersoff
            Reporter:
            David Holmes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: