pmxcfs: use glib free_and_steal when taking ownership of underlying c string
Using 'g_string_free(outbuf, FALSE)', which is equivalent to the newer ‘g_string_free_and_steal’ function, the management structure from the GLib string will be freed while the underlying "actual" char * C string won't, and thus the caller of this needs to take care of that freeing that string when not needed anymore. This is used in a few places in pmxcfs by design, as newer compiler and glib gained intrinsics to help detecting missuse one must now use the result of that function, which is the underlying char pointer, as heuristic for the caller to signal that one is aware of that contract. As we pulled out the pointer earlier directly and then called this partial free method, all worked fine but the compiler couldn't be sure about this. Adapt the code accordingly, there should be semantic change whatsoever, but it gets actually slightly shorter, which is nice. While at it also replace some uses of 1 with the TRUE constant, it's the same but it's more telling for those accustomed to code using the Glib. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
05ad6c9c11
commit
a86c4b3ba3
3 changed files with 7 additions and 14 deletions
|
|
@ -662,7 +662,7 @@ dcdb_process_state_update(
|
|||
localsi->idx = idx[i];
|
||||
}
|
||||
cfs_message("synced members: %s", synced_member_ids->str);
|
||||
g_string_free(synced_member_ids, 1);
|
||||
g_string_free(synced_member_ids, TRUE);
|
||||
|
||||
/* send update */
|
||||
if (dfsm_nodeid_is_local(dfsm, syncinfo->nodes[leader].nodeid, syncinfo->nodes[leader].pid)) {
|
||||
|
|
|
|||
|
|
@ -1158,7 +1158,7 @@ dfsm_cpg_confchg_callback(
|
|||
if ((dfsm->we_are_member || mode != DFSM_MODE_START))
|
||||
cfs_dom_message(dfsm->log_domain, "members: %s", member_ids->str);
|
||||
|
||||
g_string_free(member_ids, 1);
|
||||
g_string_free(member_ids, TRUE);
|
||||
|
||||
dfsm->lowest_nodeid = lowest_nodeid;
|
||||
|
||||
|
|
|
|||
|
|
@ -532,8 +532,7 @@ create_dot_version_cb(cfs_plug_t *plug)
|
|||
char *data = NULL;
|
||||
|
||||
if (cfs_create_version_msg(outbuf) == 0) {
|
||||
data = outbuf->str;
|
||||
g_string_free(outbuf, FALSE);
|
||||
data = g_string_free_and_steal(outbuf);
|
||||
} else {
|
||||
g_string_free(outbuf, TRUE);
|
||||
}
|
||||
|
|
@ -548,8 +547,7 @@ create_dot_members_cb(cfs_plug_t *plug)
|
|||
char *data = NULL;
|
||||
|
||||
if (cfs_create_memberlist_msg(outbuf) == 0) {
|
||||
data = outbuf->str;
|
||||
g_string_free(outbuf, FALSE);
|
||||
data = g_string_free_and_steal(outbuf);
|
||||
} else {
|
||||
g_string_free(outbuf, TRUE);
|
||||
}
|
||||
|
|
@ -564,8 +562,7 @@ create_dot_vmlist_cb(cfs_plug_t *plug)
|
|||
char *data = NULL;
|
||||
|
||||
if (cfs_create_vmlist_msg(outbuf) == 0) {
|
||||
data = outbuf->str;
|
||||
g_string_free(outbuf, FALSE);
|
||||
data = g_string_free_and_steal(outbuf);
|
||||
} else {
|
||||
g_string_free(outbuf, TRUE);
|
||||
}
|
||||
|
|
@ -579,10 +576,8 @@ create_dot_rrd_cb(cfs_plug_t *plug)
|
|||
GString *outbuf = g_string_new(NULL);
|
||||
|
||||
cfs_rrd_dump(outbuf);
|
||||
char *data = outbuf->str;
|
||||
g_string_free(outbuf, FALSE);
|
||||
|
||||
return data;
|
||||
return g_string_free_and_steal(outbuf);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
|
@ -591,10 +586,8 @@ create_dot_clusterlog_cb(cfs_plug_t *plug)
|
|||
GString *outbuf = g_string_new(NULL);
|
||||
|
||||
cfs_cluster_log_dump(outbuf, NULL, 50);
|
||||
char *data = outbuf->str;
|
||||
g_string_free(outbuf, FALSE);
|
||||
|
||||
return data;
|
||||
return g_string_free_and_steal(outbuf);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue