Skip to content

Commit 8c38e6f

Browse files
committed
Refactor: libcib: Use done label in cib__perform_op_ro()
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 9a2bfc5 commit 8c38e6f

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

lib/cib/cib_utils.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,26 +268,34 @@ cib__perform_op_ro(cib__op_fn_t fn, xmlNode *req, xmlNode **current_cib,
268268
&& (cib == xmlDocGetRootElement(cib->doc)));
269269
}
270270

271-
if (*output == NULL) {
272-
// Do nothing
271+
if (cib_filtered == *output) {
272+
// Let the caller have this copy
273+
return rc;
274+
}
273275

274-
} else if (cib_filtered == *output) {
275-
// Let them have this copy
276-
cib_filtered = NULL;
276+
if (*output == NULL) {
277+
goto done;
278+
}
277279

278-
} else if (*output == *current_cib) {
279-
// They already know not to free it
280+
if (*output == *current_cib) {
281+
// Trust the caller to check this and not free *output
282+
goto done;
283+
}
280284

281-
} else if ((cib_filtered != NULL)
282-
&& ((*output)->doc == cib_filtered->doc)) {
283-
// We're about to free the document of which *output is a part
285+
if ((*output)->doc == (*current_cib)->doc) {
286+
// Give the caller a copy that it can free
284287
*output = pcmk__xml_copy(NULL, *output);
288+
goto done;
289+
}
285290

286-
} else if ((*output)->doc == (*current_cib)->doc) {
287-
// Give them a copy they can free
288-
*output = pcmk__xml_copy(NULL, *output);
291+
if ((cib_filtered == NULL) || ((*output)->doc != cib_filtered->doc)) {
292+
goto done;
289293
}
290294

295+
// We're about to free the document of which *output is a part
296+
*output = pcmk__xml_copy(NULL, *output);
297+
298+
done:
291299
pcmk__xml_free(cib_filtered);
292300
return rc;
293301
}

0 commit comments

Comments
 (0)