res_crypto: Memory issues and uninitialized variable errors
ASTERISK-30235 Change-Id: Ia1e326e7b52cd06fd5e6c9009e3e63193c92f6cd
This commit is contained in:
parent
e33f2dcc0f
commit
e25b690d10
11
main/test.c
11
main/test.c
|
@ -316,9 +316,13 @@ void ast_test_set_result(struct ast_test *test, enum ast_test_result_state state
|
||||||
void ast_test_capture_free(struct ast_test_capture *capture)
|
void ast_test_capture_free(struct ast_test_capture *capture)
|
||||||
{
|
{
|
||||||
if (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;
|
capture->outbuf = NULL;
|
||||||
free(capture->errbuf);
|
ast_std_free(capture->errbuf);
|
||||||
capture->errbuf = NULL;
|
capture->errbuf = NULL;
|
||||||
}
|
}
|
||||||
capture->pid = -1;
|
capture->pid = -1;
|
||||||
|
@ -330,6 +334,7 @@ int ast_test_capture_command(struct ast_test_capture *capture, const char *file,
|
||||||
int fd0[2] = { -1, -1 }, fd1[2] = { -1, -1 }, fd2[2] = { -1, -1 };
|
int fd0[2] = { -1, -1 }, fd1[2] = { -1, -1 }, fd2[2] = { -1, -1 };
|
||||||
pid_t pid = -1;
|
pid_t pid = -1;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
FILE *cmd = NULL, *out = NULL, *err = NULL;
|
||||||
|
|
||||||
memset(capture, 0, sizeof(*capture));
|
memset(capture, 0, sizeof(*capture));
|
||||||
capture->pid = capture->exitcode = -1;
|
capture->pid = capture->exitcode = -1;
|
||||||
|
@ -379,8 +384,6 @@ int ast_test_capture_command(struct ast_test_capture *capture, const char *file,
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
FILE *cmd = NULL, *out = NULL, *err = NULL;
|
|
||||||
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
int wstatus, n, nfds;
|
int wstatus, n, nfds;
|
||||||
fd_set readfds, writefds;
|
fd_set readfds, writefds;
|
||||||
|
|
|
@ -49,7 +49,7 @@ static const char *old_key_dir = NULL;
|
||||||
|
|
||||||
static char *hexstring(const unsigned char *data, unsigned datalen)
|
static char *hexstring(const unsigned char *data, unsigned datalen)
|
||||||
{
|
{
|
||||||
char *buf = alloca(datalen * 2 + 1);
|
char *buf = ast_malloc(datalen * 2 + 1);
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
for (n = 0; n < datalen; ++n) {
|
for (n = 0; n < datalen; ++n) {
|
||||||
|
@ -532,6 +532,7 @@ AST_TEST_DEFINE(crypto_aes_encrypt)
|
||||||
res = AST_TEST_PASS;
|
res = AST_TEST_PASS;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
ast_free(args[KEY]);
|
||||||
ast_test_capture_free(&cap);
|
ast_test_capture_free(&cap);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -610,6 +611,7 @@ AST_TEST_DEFINE(crypto_aes_decrypt)
|
||||||
res = AST_TEST_PASS;
|
res = AST_TEST_PASS;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
ast_free(args[KEY]);
|
||||||
ast_test_capture_free(&cap);
|
ast_test_capture_free(&cap);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue