text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE404_Improper_Resource_Shutdown__open_fclose_72b.cpp
  Label Definition File: CWE404_Improper_Resource_Shutdown__open.label.xml
  Template File: source-sinks-72b.tmpl.cpp
  */
  /*
   * @description
   * CWE: 404 Improper Resource Shutdown or Release
   * BadSource:  Open a file using open()
   * Sinks: fclose
   *    GoodSink: Close the file using close()
   *    BadSink : Close the file using fclose()
   * Flow Variant: 72 Data flow: data passed in a vector from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  #include <vector>
  
  #ifdef _WIN32
  #define OPEN _open
  #define CLOSE _close
  #else
  #include <unistd.h>
  #define OPEN open
  #define CLOSE close
  #endif
  
  using namespace std;
  
  namespace CWE404_Improper_Resource_Shutdown__open_fclose_72
  {
  
  #ifndef OMITBAD
  
  void badSink(vector<int> dataVector)
  {
      /* copy data out of dataVector */
      int data = dataVector[2];
      if (data != -1)
      {
          /* FLAW: Attempt to close the file using fclose() instead of close() */
          fclose((FILE *)data);
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodB2G uses the BadSource with the GoodSink */
  void goodB2GSink(vector<int> dataVector)
  {
      int data = dataVector[2];
      if (data != -1)
      {
          /* FIX: Close the file using close() */
          CLOSE(data);
      }
  }
  
  #endif /* OMITGOOD */
  
  } /* close namespace */
  