[Asterisk-code-review] test: initialize capture structure before freeing (asterisk[master])

Philip Prindeville asteriskteam at digium.com
Fri Sep 16 14:39:06 CDT 2022


Philip Prindeville has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19276 )


Change subject: test: initialize capture structure before freeing
......................................................................

test: initialize capture structure before freeing

ASTERISK-30232 #close

Change-Id: I2603e2cef8f93f6b0a6ef39f7eac744251bb3902
---
M include/asterisk/test.h
M main/test.c
M tests/test_crypto.c
3 files changed, 40 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/76/19276/1

diff --git a/include/asterisk/test.h b/include/asterisk/test.h
index 12aed65..5ae9825 100644
--- a/include/asterisk/test.h
+++ b/include/asterisk/test.h
@@ -439,6 +439,16 @@
 })
 
 /*!
+ * \brief Initialize the capture structure.
+ *
+ * \since 19.4.0
+ *
+ * \param capture The structure describing the child process and its
+ * associated output.
+ */
+void ast_test_capture_init(struct ast_test_capture *capture);
+
+/*!
  * \brief Release the storage (buffers) associated with capturing
  * the output of an external child process.
  *
diff --git a/main/test.c b/main/test.c
index 747262c..c635222 100644
--- a/main/test.c
+++ b/main/test.c
@@ -313,6 +313,12 @@
 	test->state = state;
 }
 
+void ast_test_capture_init(struct ast_test_capture *capture)
+{
+	capture->outbuf = capture->errbuf = NULL;
+	capture->pid = capture->exitcode = -1;
+}
+
 void ast_test_capture_free(struct ast_test_capture *capture)
 {
 	if (capture) {
@@ -331,8 +337,7 @@
 	pid_t pid = -1;
 	int status = 0;
 
-	memset(capture, 0, sizeof(*capture));
-	capture->pid = capture->exitcode = -1;
+	ast_test_capture_init(capture);
 
 	if (data != NULL && datalen > 0) {
 		if (pipe(fd0) == -1) {
diff --git a/tests/test_crypto.c b/tests/test_crypto.c
index 141781b..6c6e9b5 100644
--- a/tests/test_crypto.c
+++ b/tests/test_crypto.c
@@ -105,6 +105,8 @@
 
 	ast_test_status_update(test, "Executing RSA encryption test\n");
 
+	ast_test_capture_init(&cap);
+
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
 		return res;
@@ -190,6 +192,8 @@
 
 	ast_test_status_update(test, "Executing RSA decryption test\n");
 
+	ast_test_capture_init(&cap);
+
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
 		return res;
@@ -285,6 +289,8 @@
 
 	ast_test_status_update(test, "Executing RSA signing test\n");
 
+	ast_test_capture_init(&cap);
+
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
 		return res;
@@ -396,6 +402,8 @@
 
 	ast_test_status_update(test, "Executing RSA signature verification test\n");
 
+	ast_test_capture_init(&cap);
+
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
 		return res;
@@ -491,6 +499,8 @@
 
 	ast_test_status_update(test, "Executing AES-ECB encryption test\n");
 
+	ast_test_capture_init(&cap);
+
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
 		return res;
@@ -564,6 +574,8 @@
 
 	ast_test_status_update(test, "Executing AES-ECB decryption test\n");
 
+	ast_test_capture_init(&cap);
+
 	if (!ast_check_command_in_path(command)) {
 		ast_test_status_update(test, "couldn't find %s\n", command);
 		return res;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19276
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I2603e2cef8f93f6b0a6ef39f7eac744251bb3902
Gerrit-Change-Number: 19276
Gerrit-PatchSet: 1
Gerrit-Owner: Philip Prindeville <philipp at redfish-solutions.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220916/de5b64af/attachment-0001.html>


More information about the asterisk-code-review mailing list