pmxcfs: status: avoid g_strdup when not needed

`filename_pve2` is not accessed anymore after assigning the copy to
`filename`, so we can simply 'transfer' the ownership to `filename`
and set `filenname_pve2` to NULL.

The call to `g_free(filename_pve2)` later can handle a NULL arg, it will
simply do nothing in this case.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
Tested-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Reviewed-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Link: https://lore.proxmox.com/20250801095431.117317-5-l.wagner@proxmox.com
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Lukas Wagner 2025-08-01 11:54:31 +02:00 committed by Thomas Lamprecht
parent 0795244f98
commit 054995ba3d

View file

@ -1369,7 +1369,8 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
use_pve2_file = 1;
g_free(filename);
filename = g_strdup(filename_pve2);
filename = filename_pve2;
filename_pve2 = NULL;
} else {
// neither file exists, check for directories to decide and create file
@ -1381,7 +1382,8 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
use_pve2_file = 1;
g_free(filename);
filename = g_strdup(filename_pve2);
filename = filename_pve2;
filename_pve2 = NULL;
char *dir = g_path_get_dirname(filename);
checked_mkdir(dir, 0755);
@ -1441,7 +1443,8 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
// old file exists, use it
use_pve2_file = 1;
g_free(filename);
filename = g_strdup(filename_pve2);
filename = filename_pve2;
filename_pve2 = NULL;
} else {
// neither file exists, check for directories to decide and create file
@ -1453,7 +1456,8 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
use_pve2_file = 1;
g_free(filename);
filename = g_strdup(filename_pve2);
filename = filename_pve2;
filename_pve2 = NULL;
int argcount = sizeof(rrd_def_vm) / sizeof(void *) - 1;
create_rrd_file(filename, argcount, rrd_def_vm);
@ -1507,7 +1511,8 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
} else if (g_file_test(filename_pve2, G_FILE_TEST_EXISTS)) {
// old file exists, use it
g_free(filename);
filename = g_strdup(filename_pve2);
filename = filename_pve2;
filename_pve2 = NULL;
} else {
// neither file exists, check for directories to decide and create file
@ -1520,7 +1525,8 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
create_rrd_file(filename, argcount, rrd_def_storage_pve9_0);
} else if (g_file_test(RRDDIR "/pve2-storage", G_FILE_TEST_IS_DIR)) {
g_free(filename);
filename = g_strdup(filename_pve2);
filename = filename_pve2;
filename_pve2 = NULL;
char *dir = g_path_get_dirname(filename);
checked_mkdir(dir, 0755);