safe_create_leading_directories_const(): preserve errno

Some implementations of free() change errno (even thought they shouldn't): https://sourceware.org/bugzilla/show_bug.cgi?id=17924 So preserve the errno from safe_create_leading_directories() across the call to free(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Jan 6, 2017 at 17:22 UTC 029443070a4e5b0290a2d09f3707bc486d84a961
1 file changed +4
sha1_file.c
+4
@@ -166,10 +166,14 @@ enum scld_error safe_create_leading_directories(char *path)
166
167 enum scld_error safe_create_leading_directories_const(const char *path)
168 {
169 + int save_errno;
170 /* path points to cache entries, so xstrdup before messing with it */
171 char *buf = xstrdup(path);
172 enum scld_error result = safe_create_leading_directories(buf);
173 +
174 + save_errno = errno;
175 free(buf);
176 + errno = save_errno;
177 return result;
178 }
179