qtest: do not return freed argument vector from qtest_rsp
PATCH 1/1 qtest: do not return freed argument vector from qtest_rsp
If expected_args is 0, qtest frees the argument vector and then returns it nevertheless. Coverity complains; in practice this is not an issue because expected_args == 0 means that the caller is not interested in the argument vector, but it would be a potential problem if somebody wanted to add commands with optional arguments to qtest.
--- tests/qtest/libqtest.c | 1 + 1 file changed, 1 insertion(+)
tests/qtest/libqtest.c +1 -0
@@ -545,6 +545,7 @@ redo: } }else {g_strfreev (words); + words =NULL ; }return words;
Signature · 1 line
2.28.0
Quoted 18 lines · Paolo Bonzini
If
expected_argsis 0, qtest frees the argument vector and then returns it nevertheless. Coverity complains; in practice this is not an issue becauseexpected_args== 0 means that the caller is not interested in the argument vector, but it would be a potential problem if somebody wanted to add commands with optional arguments to qtest.Suggested-by Kamil Dudka <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- tests/qtest/libqtest.c | 1 + 1 file changed, 1 insertion(+)tests/qtest/libqtest.c +0
-0
tests/qtest/libqtest.c redo: · line 551
Quoted 7 lines
tests/qtest/libqtest.c +1
-0@@ -545,6 +545,7 @@ redo: } }else {g_strfreev (words); + words =NULL ; }return words;
tests/qtest/libqtest.c redo:
Quoted 17 lines · Paolo Bonzini
If
expected_argsis 0, qtest frees the argument vector and then returns it nevertheless. Coverity complains; in practice this is not an issue becauseexpected_args== 0 means that the caller is not interested in the argument vector, but it would be a potential problem if somebody wanted to add commands with optional arguments to qtest.Suggested-by Kamil Dudka <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- tests/qtest/libqtest.c | 1 + 1 file changed, 1 insertion(+)tests/qtest/libqtest.c +0
-0@@ -545,6 +545,7 @@ redo:
if (expected_args) {
for (i = 0; i < expected_args; i++) {
g_assert(words[i] != NULL);tests/qtest/libqtest.c redo: · line 551
Quoted 7 lines
tests/qtest/libqtest.c +1
-0} }else {g_strfreev (words); + words =NULL ; }return words;
The patch is okay, so
Odd: we require at least @expected_args, but more is fine. Not what the name @expected_args made me expect.
We treat expected_args == 0 as special case to save callers the trouble to free @words. Okay, but I'd try a more regular interface:
* one function that takes @expected_args and returns @words, always.
* a simple wrapper around it that passes zero @expected_args and frees @words.