From ace8d6d6cca942f5294baffc1b9feee14ec9a9f0 Mon Sep 17 00:00:00 2001 From: d4ndox Date: Wed, 8 May 2024 18:13:22 +0200 Subject: [PATCH] Fixed Segemtation fault:calling --cleanup or init. --- mnp.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/mnp.c b/mnp.c index 867424b..0676cd8 100644 --- a/mnp.c +++ b/mnp.c @@ -216,32 +216,31 @@ int main(int argc, char **argv) if (txid == NULL) { txid = readStdin(); } - } - FILE *file = fopen(TMP_TXID_FILE, "a+"); - if (file == NULL) { - perror("Error opening tmp file"); - exit(EXIT_FAILURE); - } + FILE *file = fopen(TMP_TXID_FILE, "a+"); + if (file == NULL) { + perror("Error opening tmp file"); + exit(EXIT_FAILURE); + } - /* Test, if the current txid is already existing in temp file */ - // Überprüfen, ob der aktuelle txid bereits in der Datei vorhanden ist - char line[MAX_TXID_SIZE + 1]; - int txid_found = 0; - while (fgets(line, sizeof(line), file)) { - line[strcspn(line, "\n")] = '\0'; // Entferne das Zeilenumbruchzeichen - if (strncmp(line, txid, MAX_TXID_SIZE) == 0) { - txid_found = 1; - break; + /* Test, if the current txid is already existing in temp file */ + char line[MAX_TXID_SIZE + 1]; + int txid_found = 0; + while (fgets(line, sizeof(line), file)) { + line[strcspn(line, "\n")] = '\0'; // Entferne das Zeilenumbruchzeichen + if (strncmp(line, txid, MAX_TXID_SIZE) == 0) { + txid_found = 1; + break; + } } - } - /* If the current txid is not found in temp file, add it to the file */ - if (!txid_found) { - fprintf(file, "%s\n", txid); - fclose(file); - } else { - exit(EXIT_SUCCESS); + /* If the current txid is not found in temp file, add it to the file */ + if (!txid_found) { + fprintf(file, "%s\n", txid); + fclose(file); + } else { + exit(EXIT_SUCCESS); + } } char *perm = strndup(config.cfg_mode, MAX_DATA_SIZE);