Skip to content

Commit 61a31dc

Browse files
committed
fix: add missing delwin for shader_cores/l2_cache_size/exec_engines, plot_window, and unsigned underflow guard
- free_device_windows: delwin() for shader_cores, l2_cache_size, exec_engines (upstream PR Syllo#467 fix/memory-leaks-in-free-device-windows) - delete_all_windows: delwin() for plots[i].plot_window (upstream PR Syllo#468 fix/plot-window-memory-leak) - nvtop_get_nvlink_info: guard against unsigned underflow in CLI throughput delta if hardware counter wraps or resets
1 parent 4b1f9f2 commit 61a31dc

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/extract_gpuinfo_nvidia.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,13 @@ unsigned nvtop_get_nvlink_info(struct gpu_info *_gpu_info, struct nvlink_info *n
12371237

12381238
unsigned long long total_tx = 0, total_rx = 0;
12391239
for (unsigned int link = 0; link < linkCount; link++) {
1240-
total_tx += cli_tx[link] - gpu_info->nvlink_cli_tx[link];
1241-
total_rx += cli_rx[link] - gpu_info->nvlink_cli_rx[link];
1240+
// Guard against unsigned underflow if the hardware counter wraps or resets.
1241+
// If the new reading is less than the stored reading, skip this link to
1242+
// avoid a delta near ULLONG_MAX that would produce an absurd throughput spike.
1243+
if (cli_tx[link] >= gpu_info->nvlink_cli_tx[link])
1244+
total_tx += cli_tx[link] - gpu_info->nvlink_cli_tx[link];
1245+
if (cli_rx[link] >= gpu_info->nvlink_cli_rx[link])
1246+
total_rx += cli_rx[link] - gpu_info->nvlink_cli_rx[link];
12421247
}
12431248
// Raw rate (no smoothing — accuracy is more important than display smoothness)
12441249
gpu_info->smoothed_agg_tx = (unsigned long long)((double)total_tx / delta_s);

src/interface.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ static void free_device_windows(struct device_window *dwin) {
252252
delwin(dwin->temperature);
253253
delwin(dwin->fan_speed);
254254
delwin(dwin->pcie_info);
255+
// Upstream bug: shader_cores, l2_cache_size, exec_engines were allocated with
256+
// newwin() in alloc_device_window() but never freed here. This leaks 3 WINDOW
257+
// structs per device on every delete_all_windows() call (terminal resize, GPU set change).
258+
// Also fixed in upstream PR #467 (fix/memory-leaks-in-free-device-windows).
259+
delwin(dwin->shader_cores);
260+
delwin(dwin->l2_cache_size);
261+
delwin(dwin->exec_engines);
255262
if (dwin->nvlink_info != NULL)
256263
delwin(dwin->nvlink_info);
257264
if (dwin->nvlink_errors != NULL)
@@ -459,6 +466,11 @@ static void delete_all_windows(struct nvtop_interface *dwin) {
459466
delwin(dwin->process.option_window.option_win);
460467
for (size_t i = 0; i < dwin->num_plots; ++i) {
461468
delwin(dwin->plots[i].win);
469+
// Upstream bug: plot_window was allocated with newwin() in
470+
// initialize_gpu_mem_plot() but never freed here. This leaks one WINDOW
471+
// struct per chart on every delete_all_windows() call.
472+
// Also fixed in upstream PR #468 (fix/plot-window-memory-leak).
473+
delwin(dwin->plots[i].plot_window);
462474
free(dwin->plots[i].data);
463475
}
464476
free_setup_window(&dwin->setup_win);

0 commit comments

Comments
 (0)