Partager via


C6335

Avertissement C6335 : handle d'informations de processus manquant <NomHandle>

Cet avertissement indique que les handles d'informations de processus retournés par la famille de fonctions CreateProcess doivent être fermés à l'aide de CloseHandle. Sinon, des fuites de handle risquent de se produire.

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 Fonction CreateProcess (page éventuellement en anglais) et Fonction CloseHandle (page éventuellement en anglais).