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;
}
...
[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;
}
...