[Asterisk-code-review] res_crypto: Memory issues and and uninitialized variable error (asterisk[19])

George Joseph asteriskteam at digium.com
Fri Sep 16 10:12:07 CDT 2022


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19269 )


Change subject: res_crypto: Memory issues and and uninitialized variable error
......................................................................

res_crypto: Memory issues and and uninitialized variable error

ASTERISK-30235

Change-Id: Ia1e326e7b52cd06fd5e6c9009e3e63193c92f6cd
---
M main/test.c
M tests/test_crypto.c
2 files changed, 21 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/19269/1

diff --git a/main/test.c b/main/test.c
index 747262c..03de33b 100644
--- a/main/test.c
+++ b/main/test.c
@@ -316,9 +316,13 @@
 void ast_test_capture_free(struct ast_test_capture *capture)
 {
 	if (capture) {
-		free(capture->outbuf);
+		/*
+		 * Need to use ast_std_free because this memory wasn't
+		 * allocated by the astmm functions.
+		 */
+		ast_std_free(capture->outbuf);
 		capture->outbuf = NULL;
-		free(capture->errbuf);
+		ast_std_free(capture->errbuf);
 		capture->errbuf = NULL;
 	}
 	capture->pid = -1;
@@ -330,6 +334,7 @@
 	int fd0[2] = { -1, -1 }, fd1[2] = { -1, -1 }, fd2[2] = { -1, -1 };
 	pid_t pid = -1;
 	int status = 0;
+	FILE *cmd = NULL, *out = NULL, *err = NULL;
 
 	memset(capture, 0, sizeof(*capture));
 	capture->pid = capture->exitcode = -1;
@@ -379,8 +384,6 @@
 		exit(1);
 
 	} else {
-		FILE *cmd = NULL, *out = NULL, *err = NULL;
-
 		char buf[BUFSIZ];
 		int wstatus, n, nfds;
 		fd_set readfds, writefds;
diff --git a/tests/test_crypto.c b/tests/test_crypto.c
index 141781b..a3a0004 100644
--- a/tests/test_crypto.c
+++ b/tests/test_crypto.c
@@ -49,7 +49,7 @@
 
 static char *hexstring(const unsigned char *data, unsigned datalen)
 {
-	char *buf = alloca(datalen * 2 + 1);
+	char *buf = ast_malloc(datalen * 2 + 1);
 	unsigned n;
 
 	for (n = 0; n < datalen; ++n) {
@@ -532,6 +532,7 @@
 	res = AST_TEST_PASS;
 
 cleanup:
+	ast_free(args[KEY]);
 	ast_test_capture_free(&cap);
 	return res;
 }
@@ -610,6 +611,7 @@
 	res = AST_TEST_PASS;
 
 cleanup:
+	ast_free(args[KEY]);
 	ast_test_capture_free(&cap);
 	return res;
 }

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

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: Ia1e326e7b52cd06fd5e6c9009e3e63193c92f6cd
Gerrit-Change-Number: 19269
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220916/12112df9/attachment.html>


More information about the asterisk-code-review mailing list