diff --git a/src/audio.c b/src/audio.c index 8b927ea..3cd2cd0 100644 --- a/src/audio.c +++ b/src/audio.c @@ -32,9 +32,12 @@ int audio_init(audio_t *aud, int channels, int sample_rate, int frame_size) { aud->buffer_size = frame_size * channels; aud->buffer = (audio_sample_t *)malloc(aud->buffer_size * sizeof(audio_sample_t)); + if (aud->buffer == NULL) + return -1; if ((pa_err = Pa_StartStream(aud->stream)) != paNoError) { fprintf(stderr, "Cannot start a PortAudio stream: %s\n", Pa_GetErrorText(pa_err)); + free(aud->buffer); return -1; } diff --git a/src/crypt.c b/src/crypt.c index d134119..220b92c 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -105,12 +105,16 @@ int crypt_store_key(const crypt_key_t *const k, FILE *const pub, FILE *const sec unsigned char *crypt_hello(const crypt_key_t *const own) { unsigned char *hello = (unsigned char *)malloc(CRYPT_HELLO_LEN * sizeof(unsigned char)); + if (hello == NULL) + return NULL; if (crypt_key_export_public(own, (char *const)hello) == -1) { + free(hello); return NULL; } if (crypto_sign_detached(hello+CRYPT_PKEY_HEXLEN, NULL, (const unsigned char *)hello, CRYPT_PKEY_HEXLEN, own->sign_sec) == -1) { + free(hello); return NULL; } @@ -167,8 +171,11 @@ int crypt_session_init(crypt_session_t *const s, const crypt_key_t *const own, c unsigned char *crypt_session_encrypt(crypt_session_t *const s, const unsigned char *const m, unsigned long long mlen, unsigned long long *clen) { unsigned char *c = (unsigned char *)malloc((mlen + crypto_aead_aegis256_ABYTES) * sizeof(unsigned char)); + if (c == NULL) + return NULL; if (crypto_aead_aegis256_encrypt(c, clen, m, mlen, NULL, 0, NULL, s->nonce, s->tx) == -1) { + free(c); return NULL; }