Avertissement C6335
Fuite d’informations de processus de handle 'handlename'
Notes
Cet avertissement indique que les informations de processus gérées par la famille de fonctions CreateProcess doivent être fermées à l’aide de CloseHandle. L’échec de cette opération entraîne des fuites de gestion.
Nom de l’analyse du code : LEAKING_PROCESS_HANDLE
Exemple
Le code suivant génère cet avertissement :
#include <windows.h>
#include <stdio.h>
void f( )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( "C:\\WINDOWS\\system32\\calc.exe",
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si, // Pointer to STARTUPINFO structure.
&pi ) ) // Pointer to PROCESS_INFORMATION
{
puts("Error");
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
}
Pour corriger cet avertissement, appelez CloseHandle (pi.``hThread)
pour fermer le handle de thread, comme indiqué dans le code suivant :
#include <windows.h>
#include <stdio.h>
void f( )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( "C:\\WINDOWS\\system32\\calc.exe",
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si, // Pointer to STARTUPINFO structure.
&pi ) ) // Pointer to PROCESS_INFORMATION
{
puts("Error");
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
Pour plus d’informations, consultez CreateProcess Function et CloseHandle, fonction.
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour