diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2019-08-22 17:57:09 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2019-08-22 17:57:09 +0100 |
commit | 3590b27c7a2be7a24b4b265e2e9458b3761103e1 (patch) | |
tree | c4f94fe22dc14be0929494f0c9688ab4a84c65fd /crypto/afsplit.c | |
parent | d013d220c710054a6d755941460f88c186fef7b5 (diff) | |
parent | 57b9f113fce2a2231a47e9295c1d461e9ff7f0f7 (diff) | |
download | qemu-3590b27c7a2be7a24b4b265e2e9458b3761103e1.zip qemu-3590b27c7a2be7a24b4b265e2e9458b3761103e1.tar.gz qemu-3590b27c7a2be7a24b4b265e2e9458b3761103e1.tar.bz2 |
Merge remote-tracking branch 'remotes/berrange/tags/autofree-pull-request' into staging
require newer glib2 to enable autofree'ing of stack variables exiting scope
* Bump minium glib2 version to 2.48
* Convert much of the crypto code to use automatic memory free functions
# gpg: Signature made Thu 22 Aug 2019 11:51:59 BST
# gpg: using RSA key DAF3A6FDB26B62912D0E8E3FBE86EBB415104FDF
# gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full]
# gpg: aka "Daniel P. Berrange <berrange@redhat.com>" [full]
# Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E 8E3F BE86 EBB4 1510 4FDF
* remotes/berrange/tags/autofree-pull-request:
crypto: use auto cleanup for many stack variables
crypto: define cleanup functions for use with g_autoptr
glib: bump min required glib library version to 2.48
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'crypto/afsplit.c')
-rw-r--r-- | crypto/afsplit.c | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/crypto/afsplit.c b/crypto/afsplit.c index 328d68c..b1a5a20 100644 --- a/crypto/afsplit.c +++ b/crypto/afsplit.c @@ -58,7 +58,7 @@ static int qcrypto_afsplit_hash(QCryptoHashAlgorithm hash, } for (i = 0; i < hashcount; i++) { - uint8_t *out = NULL; + g_autofree uint8_t *out = NULL; size_t outlen = 0; uint32_t iv = cpu_to_be32(i); struct iovec in[] = { @@ -79,7 +79,6 @@ static int qcrypto_afsplit_hash(QCryptoHashAlgorithm hash, assert(outlen == digestlen); memcpy(block + (i * digestlen), out, (i == (hashcount - 1)) ? finallen : digestlen); - g_free(out); } return 0; @@ -93,13 +92,12 @@ int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash, uint8_t *out, Error **errp) { - uint8_t *block = g_new0(uint8_t, blocklen); + g_autofree uint8_t *block = g_new0(uint8_t, blocklen); size_t i; - int ret = -1; for (i = 0; i < (stripes - 1); i++) { if (qcrypto_random_bytes(out + (i * blocklen), blocklen, errp) < 0) { - goto cleanup; + return -1; } qcrypto_afsplit_xor(blocklen, @@ -108,18 +106,14 @@ int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash, block); if (qcrypto_afsplit_hash(hash, blocklen, block, errp) < 0) { - goto cleanup; + return -1; } } qcrypto_afsplit_xor(blocklen, in, block, out + (i * blocklen)); - ret = 0; - - cleanup: - g_free(block); - return ret; + return 0; } @@ -130,9 +124,8 @@ int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash, uint8_t *out, Error **errp) { - uint8_t *block = g_new0(uint8_t, blocklen); + g_autofree uint8_t *block = g_new0(uint8_t, blocklen); size_t i; - int ret = -1; for (i = 0; i < (stripes - 1); i++) { qcrypto_afsplit_xor(blocklen, @@ -141,7 +134,7 @@ int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash, block); if (qcrypto_afsplit_hash(hash, blocklen, block, errp) < 0) { - goto cleanup; + return -1; } } @@ -149,10 +142,5 @@ int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash, in + (i * blocklen), block, out); - - ret = 0; - - cleanup: - g_free(block); - return ret; + return 0; } |