diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index 5e4b555..bffc9da 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -3832,7 +3832,9 @@
     if (!ConvertStringSecurityDescriptorToSecurityDescriptor(sddlString, SDDL_REVISION_1, &sd,
                                                              NULL))
     {
-        MsgToEventLog(M_SYSERR, L"ConvertStringSecurityDescriptorToSecurityDescriptor failed.");
+        DWORD error =
+            MsgToEventLog(M_SYSERR, L"ConvertStringSecurityDescriptorToSecurityDescriptor failed.");
+        SetLastError(error);
         return INVALID_HANDLE_VALUE;
     }
 
@@ -3871,14 +3873,15 @@
                                &sa);
     }
 
-    LocalFree(sd);
-
     if (pipe == INVALID_HANDLE_VALUE)
     {
-        MsgToEventLog(M_SYSERR, L"Could not create named pipe");
+        DWORD error = MsgToEventLog(M_SYSERR, L"Could not create named pipe");
+        LocalFree(sd);
+        SetLastError(error);
         return INVALID_HANDLE_VALUE;
     }
 
+    LocalFree(sd);
     return pipe;
 }
 
@@ -4043,6 +4046,7 @@
     pipe = CreateClientPipeInstance();
     if (pipe == INVALID_HANDLE_VALUE)
     {
+        error = GetLastError();
         goto out;
     }
 
