diff --git a/salty.c b/salty.c index 3faf6bc..75dabc9 100644 --- a/salty.c +++ b/salty.c @@ -123,6 +123,7 @@ int encryptMessage(const char* inputFile, const char* outputFile, const char* pa fprintf(stderr,ERR"Error reading from file.\n"); fclose(inFile); fclose(outFile); + free(decrypted); return 1; } fclose(inFile); @@ -145,6 +146,8 @@ int encryptMessage(const char* inputFile, const char* outputFile, const char* pa unsigned char* outputBuffer = malloc(totalSize); if (outputBuffer == NULL) { fprintf(stderr,ERR"Memory allocation error.\n"); + free(decrypted); + fclose(outFile); return 1; } memcpy(outputBuffer + offset, "gneurshk", strlen("gneurshk")); @@ -268,6 +271,7 @@ int decryptMessage(const char* inputFile, const char* outputFile, const char* pa if (memcmp(fullInput,"gneurshk",strlen("gneurshk")) != 0) { fprintf(stderr,ERR"Invalid header.\n"); fprintf(stderr,ERR"Make sure the input file was signed by this program!\n"); + free(fullInput); fclose(outFile); return 1; } @@ -289,6 +293,8 @@ int decryptMessage(const char* inputFile, const char* outputFile, const char* pa unsigned char key[KEY_SIZE]; if (!keyGen(salt,password,key)) { + free(fullInput); + fclose(outFile); return 1; } @@ -299,18 +305,21 @@ int decryptMessage(const char* inputFile, const char* outputFile, const char* pa if (crypto_secretbox_open_easy(decrypted,encrypted,encLen,nonce,key) < 0) { fprintf(stderr,ERR"Error decrypting file.\n"); + free(fullInput); fclose(outFile); return 1; } if (fwrite(decrypted,1,decLen,outFile) != decLen) { fprintf(stderr,ERR"Error writing data to file.\n"); + free(fullInput); fclose(outFile); return 1; } fclose(outFile); - + free(fullInput); + fprintf(stderr,"\n"OK"File decrypted!\n"); return 0;