Repository navigation
Annotate credential output buffers with CredFree ownership - #2389
Open
Jevan Saks (jevansaks) with Copilot wants to merge 2 commits into
Open
Jevan Saks (jevansaks) with Copilot wants to merge 2 commits into
Jevan Saks (jevansaks) with Copilot wants to merge 2 commits into
Conversation
Co-authored-by: jevansaks <20667023+jevansaks@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add CredRead, CredEnumerate annotations for CredFree
Annotate credential output buffers with CredFree ownership
Oct 26, 2026
Jevan Saks (jevansaks)
approved these changes
Oct 26, 2026
Jevan Saks (jevansaks)
marked this pull request as ready for review
October 26, 2026 17:35
Jevan Saks (jevansaks)
requested review from
a team and
Vineeth Thomas Alex (vineeththomasalex)
as code owners
October 26, 2026 17:35
📋 API Surface Diff+14 additions / -14 deletions vs main branch (full validation run) Click to expand API diffdiff --git "a/bin\\baseline.apidump.cs" "b/bin\\current.apidump.cs"
index bc6e749a..65da4c6f 100644
--- "a/bin\\baseline.apidump.cs"
+++ "b/bin\\current.apidump.cs"
@@ -516501,25 +516501,25 @@ public static class Apis
[SupportedOSPlatform ("windows5.1.2600")]
[Unicode]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credreadw")]
- public unsafe static extern BOOL CredReadW ([In][Const] PWSTR TargetName, [In] CRED_TYPE Type, [Optional][Reserved] uint Flags, [Out] CREDENTIALW** Credential);
+ public unsafe static extern BOOL CredReadW ([In][Const] PWSTR TargetName, [In] CRED_TYPE Type, [Optional][Reserved] uint Flags, [Out][FreeWith ("CredFree")] CREDENTIALW** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Ansi]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credreada")]
- public unsafe static extern BOOL CredReadA ([In][Const] PSTR TargetName, [In] CRED_TYPE Type, [Optional][Reserved] uint Flags, [Out] CREDENTIALA** Credential);
+ public unsafe static extern BOOL CredReadA ([In][Const] PSTR TargetName, [In] CRED_TYPE Type, [Optional][Reserved] uint Flags, [Out][FreeWith ("CredFree")] CREDENTIALA** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Unicode]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credenumeratew")]
- public unsafe static extern BOOL CredEnumerateW ([Optional][In][Const] PWSTR Filter, [Optional][Reserved] CRED_ENUMERATE_FLAGS Flags, [Out] uint* Count, [Out] CREDENTIALW*** Credential);
+ public unsafe static extern BOOL CredEnumerateW ([Optional][In][Const] PWSTR Filter, [Optional][Reserved] CRED_ENUMERATE_FLAGS Flags, [Out] uint* Count, [Out][FreeWith ("CredFree")] CREDENTIALW*** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Ansi]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credenumeratea")]
- public unsafe static extern BOOL CredEnumerateA ([Optional][In][Const] PSTR Filter, [Optional][Reserved] CRED_ENUMERATE_FLAGS Flags, [Out] uint* Count, [Out] CREDENTIALA*** Credential);
+ public unsafe static extern BOOL CredEnumerateA ([Optional][In][Const] PSTR Filter, [Optional][Reserved] CRED_ENUMERATE_FLAGS Flags, [Out] uint* Count, [Out][FreeWith ("CredFree")] CREDENTIALA*** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
@@ -516537,13 +516537,13 @@ public static class Apis
[SupportedOSPlatform ("windows5.1.2600")]
[Unicode]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credreaddomaincredentialsw")]
- public unsafe static extern BOOL CredReadDomainCredentialsW ([In] CREDENTIAL_TARGET_INFORMATIONW* TargetInfo, [In] uint Flags, [Out] uint* Count, [Out] CREDENTIALW*** Credential);
+ public unsafe static extern BOOL CredReadDomainCredentialsW ([In] CREDENTIAL_TARGET_INFORMATIONW* TargetInfo, [In] uint Flags, [Out] uint* Count, [Out][FreeWith ("CredFree")] CREDENTIALW*** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Ansi]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credreaddomaincredentialsa")]
- public unsafe static extern BOOL CredReadDomainCredentialsA ([In] CREDENTIAL_TARGET_INFORMATIONA* TargetInfo, [In] uint Flags, [Out] uint* Count, [Out] CREDENTIALA*** Credential);
+ public unsafe static extern BOOL CredReadDomainCredentialsA ([In] CREDENTIAL_TARGET_INFORMATIONA* TargetInfo, [In] uint Flags, [Out] uint* Count, [Out][FreeWith ("CredFree")] CREDENTIALA*** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
@@ -516573,37 +516573,37 @@ public static class Apis
[SupportedOSPlatform ("windows5.1.2600")]
[Unicode]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credgettargetinfow")]
- public unsafe static extern BOOL CredGetTargetInfoW ([In][Const] PWSTR TargetName, [In] uint Flags, [Out] CREDENTIAL_TARGET_INFORMATIONW** TargetInfo);
+ public unsafe static extern BOOL CredGetTargetInfoW ([In][Const] PWSTR TargetName, [In] uint Flags, [Out][FreeWith ("CredFree")] CREDENTIAL_TARGET_INFORMATIONW** TargetInfo);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Ansi]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credgettargetinfoa")]
- public unsafe static extern BOOL CredGetTargetInfoA ([In][Const] PSTR TargetName, [In] uint Flags, [Out] CREDENTIAL_TARGET_INFORMATIONA** TargetInfo);
+ public unsafe static extern BOOL CredGetTargetInfoA ([In][Const] PSTR TargetName, [In] uint Flags, [Out][FreeWith ("CredFree")] CREDENTIAL_TARGET_INFORMATIONA** TargetInfo);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Unicode]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credmarshalcredentialw")]
- public unsafe static extern BOOL CredMarshalCredentialW ([In] CRED_MARSHAL_TYPE CredType, [In] void* Credential, [Out] PWSTR* MarshaledCredential);
+ public unsafe static extern BOOL CredMarshalCredentialW ([In] CRED_MARSHAL_TYPE CredType, [In] void* Credential, [Out][FreeWith ("CredFree")] PWSTR* MarshaledCredential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Ansi]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credmarshalcredentiala")]
- public unsafe static extern BOOL CredMarshalCredentialA ([In] CRED_MARSHAL_TYPE CredType, [In] void* Credential, [Out] PSTR* MarshaledCredential);
+ public unsafe static extern BOOL CredMarshalCredentialA ([In] CRED_MARSHAL_TYPE CredType, [In] void* Credential, [Out][FreeWith ("CredFree")] PSTR* MarshaledCredential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Unicode]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credunmarshalcredentialw")]
- public unsafe static extern BOOL CredUnmarshalCredentialW ([In][Const] PWSTR MarshaledCredential, [Out] CRED_MARSHAL_TYPE* CredType, [Out] void** Credential);
+ public unsafe static extern BOOL CredUnmarshalCredentialW ([In][Const] PWSTR MarshaledCredential, [Out] CRED_MARSHAL_TYPE* CredType, [Out][FreeWith ("CredFree")] void** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
[Ansi]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credunmarshalcredentiala")]
- public unsafe static extern BOOL CredUnmarshalCredentialA ([In][Const] PSTR MarshaledCredential, [Out] CRED_MARSHAL_TYPE* CredType, [Out] void** Credential);
+ public unsafe static extern BOOL CredUnmarshalCredentialA ([In][Const] PSTR MarshaledCredential, [Out] CRED_MARSHAL_TYPE* CredType, [Out][FreeWith ("CredFree")] void** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false)]
[SupportedOSPlatform ("windows5.1.2600")]
@@ -516681,13 +516681,13 @@ public static class Apis
[SupportedOSPlatform ("windows6.0.6000")]
[Unicode]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credfindbestcredentialw")]
- public unsafe static extern BOOL CredFindBestCredentialW ([In][Const] PWSTR TargetName, [In] uint Type, [In] uint Flags, [Out] CREDENTIALW** Credential);
+ public unsafe static extern BOOL CredFindBestCredentialW ([In][Const] PWSTR TargetName, [In] uint Type, [In] uint Flags, [Out][FreeWith ("CredFree")] CREDENTIALW** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows6.0.6000")]
[Ansi]
[Documentation ("https://learn.microsoft.com/windows/win32/api/wincred/nf-wincred-credfindbestcredentiala")]
- public unsafe static extern BOOL CredFindBestCredentialA ([In][Const] PSTR TargetName, [In] uint Type, [In] uint Flags, [Out] CREDENTIALA** Credential);
+ public unsafe static extern BOOL CredFindBestCredentialA ([In][Const] PSTR TargetName, [In] uint Type, [In] uint Flags, [Out][FreeWith ("CredFree")] CREDENTIALA** Credential);
[DllImport ("ADVAPI32.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform ("windows5.1.2600")]
|
Jevan Saks (jevansaks)
enabled auto-merge (squash)
October 26, 2026 19:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Credential APIs lack output ownership annotations, so CsWin32 projects raw pointers instead of owned outputs released through
CredFree.[FreeWith("CredFree")]entries inemitter.settings.rspfor A/W variants ofCredRead,CredEnumerate,CredGetTargetInfo, andCredReadDomainCredentials.CredMarshalCredential,CredUnmarshalCredential, andCredFindBestCredential.[FreeWith("CredFree")]annotations #2388