From 4ef4fbf16eca01b40176a830bfa6a8ada95e357b Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sat, 18 Nov 2017 22:32:21 +0100 Subject: Args.c: simplify nxagentProcessOptionsFile() --- nx-X11/programs/Xserver/hw/nxagent/Args.c | 36 ++++++++++++++----------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index 72926fd60..2b8d44388 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -1592,8 +1592,8 @@ void nxagentProcessOptions(char * string) void nxagentProcessOptionsFile(char * filename) { - FILE *file; - char *data; + FILE *file = NULL; + char *data = NULL; int offset; int size; @@ -1629,7 +1629,7 @@ void nxagentProcessOptionsFile(char * filename) fprintf(stderr, "Warning: Couldn't position inside option file '%s'. Error is '%s'.\n", validateString(filename), strerror(errno)); - goto nxagentProcessOptionsFileClose; + goto nxagentProcessOptionsFileExit; } if ((sizeOfFile = ftell(file)) == -1) @@ -1637,7 +1637,7 @@ void nxagentProcessOptionsFile(char * filename) fprintf(stderr, "Warning: Couldn't get the size of option file '%s'. Error is '%s'.\n", validateString(filename), strerror(errno)); - goto nxagentProcessOptionsFileClose; + goto nxagentProcessOptionsFileExit; } #ifdef DEBUG @@ -1652,7 +1652,7 @@ void nxagentProcessOptionsFile(char * filename) fprintf(stderr, "Warning: Maximum file size exceeded for options '%s'.\n", validateString(filename)); - goto nxagentProcessOptionsFileClose; + goto nxagentProcessOptionsFileExit; } if ((data = malloc(sizeOfFile + 1)) == NULL) @@ -1660,7 +1660,7 @@ void nxagentProcessOptionsFile(char * filename) fprintf(stderr, "Warning: Memory allocation failed processing file '%s'.\n", validateString(filename)); - goto nxagentProcessOptionsFileClose; + goto nxagentProcessOptionsFileExit; } offset = 0; @@ -1675,7 +1675,7 @@ void nxagentProcessOptionsFile(char * filename) fprintf(stderr, "Warning: Error reading the option file '%s'.\n", validateString(filename)); - goto nxagentProcessOptionsFileFree; + goto nxagentProcessOptionsFileExit; } size += result; @@ -1692,7 +1692,7 @@ void nxagentProcessOptionsFile(char * filename) fprintf(stderr, "Warning: Premature end of option file '%s' while reading.\n", validateString(filename)); - goto nxagentProcessOptionsFileFree; + goto nxagentProcessOptionsFileExit; } /* @@ -1705,23 +1705,19 @@ void nxagentProcessOptionsFile(char * filename) nxagentParseOptionString(data); -nxagentProcessOptionsFileFree: - - if (data != NULL) - { - free(data); - } +nxagentProcessOptionsFileExit: -nxagentProcessOptionsFileClose: + free(data); - if (fclose(file) != 0) + if (file) { - fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n", - validateString(filename), strerror(errno)); + if (fclose(file) != 0) + { + fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n", + validateString(filename), strerror(errno)); + } } -nxagentProcessOptionsFileExit: - return; } -- cgit v1.2.3