Skip to content

Commit af784ad

Browse files
committed
fixup! introduce PasswordExpiryUTC and OAuthRefreshToken
Marshal.FreeHGlobal and Marshal.DestroyStructure
1 parent 60224e0 commit af784ad

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/shared/Core/Interop/Windows/WindowsCredentialManager.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public void AddOrUpdate(string service, ICredential credential)
4848

4949
IntPtr existingCredPtr = IntPtr.Zero;
5050
IntPtr credBlob = IntPtr.Zero;
51+
IntPtr expiryPtr = IntPtr.Zero;
52+
IntPtr attributesPtr = IntPtr.Zero;
5153

5254
try
5355
{
@@ -101,7 +103,7 @@ public void AddOrUpdate(string service, ICredential credential)
101103
if (credential.PasswordExpiry != null)
102104
{
103105
byte[] expiryBytes = BitConverter.GetBytes(credential.PasswordExpiry.Value.ToUnixTimeSeconds());
104-
IntPtr expiryPtr = Marshal.AllocHGlobal(expiryBytes.Length);
106+
expiryPtr = Marshal.AllocHGlobal(expiryBytes.Length);
105107
Marshal.Copy(expiryBytes, 0, expiryPtr, expiryBytes.Length);
106108

107109
var attribute = new Win32CredentialAttribute()
@@ -113,8 +115,9 @@ public void AddOrUpdate(string service, ICredential credential)
113115
};
114116

115117
newCred.AttributeCount = 1;
116-
newCred.Attributes = Marshal.AllocHGlobal(Marshal.SizeOf(attribute));
117-
Marshal.StructureToPtr(attribute, newCred.Attributes, false);
118+
attributesPtr = Marshal.AllocHGlobal(Marshal.SizeOf(attribute));
119+
Marshal.StructureToPtr(attribute, attributesPtr, false);
120+
newCred.Attributes = attributesPtr;
118121
}
119122

120123
int result = Win32Error.GetLastError(
@@ -134,6 +137,17 @@ public void AddOrUpdate(string service, ICredential credential)
134137
{
135138
Advapi32.CredFree(existingCredPtr);
136139
}
140+
141+
if (expiryPtr != IntPtr.Zero)
142+
{
143+
Marshal.FreeHGlobal(expiryPtr);
144+
}
145+
146+
if (attributesPtr != IntPtr.Zero)
147+
{
148+
Marshal.DestroyStructure<Win32CredentialAttribute>(attributesPtr);
149+
Marshal.FreeHGlobal(attributesPtr);
150+
}
137151
}
138152
}
139153

0 commit comments

Comments
 (0)