From 53e8a30249b557e1f70fa17bba92b87ebf06cb1f Mon Sep 17 00:00:00 2001
From: echo-devim <devim@outlook.it>
Date: Thu, 22 Feb 2018 09:04:38 +0100
Subject: [PATCH] Memory leak in _synctex_open function

In the _synctex_open function, the variable build_output is never freed
producing a memory leak.

The patch handles the multiple return codes freeing the memory before to
return to the caller.
---
 cut-n-paste/synctex/synctex_parser.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/cut-n-paste/synctex/synctex_parser.c b/cut-n-paste/synctex/synctex_parser.c
index f4d96331..5444baa3 100644
--- a/cut-n-paste/synctex/synctex_parser.c
+++ b/cut-n-paste/synctex/synctex_parser.c
@@ -2878,7 +2878,8 @@ int _synctex_open(const char * output, const char * build_directory, char ** syn
 				build_output[0] = '\0';
 			} else {
 				if (build_output != strcpy(build_output,output)) {
-					return -4;
+					result = -4;
+					goto return_on_error;
 				}
 				build_output[lpc-output]='\0';
 			}
@@ -2886,17 +2887,22 @@ int _synctex_open(const char * output, const char * build_directory, char ** syn
 				/*	Append a path separator if necessary. */
 				if (!SYNCTEX_IS_PATH_SEPARATOR(build_output[strlen(build_directory)-1])) {
 					if (build_output != strcat(build_output,"/")) {
-						return -2;
+						result = -2;
+						goto return_on_error;
 					}
 				}
 				/*	Append the last path component of the output. */
 				if (build_output != strcat(build_output,lpc)) {
-					return -3;
+					result = -3;
+					goto return_on_error;
 				}
-				return __synctex_open(build_output,synctex_name_ref,file_ref,add_quotes,io_mode_ref);
+				result = __synctex_open(build_output,synctex_name_ref,file_ref,add_quotes,io_mode_ref);
 			}
+return_on_error:
+			free(build_output);
+		} else {
+			result = -1;
 		}
-		return -1;
 	}
 	return result;
 #	undef synctex_name
-- 
2.15.1

