title: Segmentation fault when using libsqora.so.19.1 by multiple threads on Linux (CentOS 7)
body: <p>I am developing an application that is using the ODBC API directly by using the Oracel DB driver.
  Everything worked fine as long I was running single threaded. But when I am using multiple threads then almost every SQL... function crashes the process.
  Whatever I found seems to be that I am doing everything correctly, e.g. I establish the environment first and after that all threads just use the environment to create their own connection.
  Calling SQLAlloc to get a connection handle still works, but calling SQLDriverConnectW results to a segmentation fault.</p>
  
  <p>Then I made a very simple test program and I get the same result (I dropped handling the return code to make it short):</p>
  
  <pre><code>SQLHANDLE environmentHandle = SQL_NULL_HENV;
  
  void testConnect() {
      SQLHANDLE connectionHandle = SQL_NULL_HDBC;
  
      SQLAllocHandle(SQL_HANDLE_DBC, environmentHandle, &amp;connectionHandle);
      SQLSetConnectAttrW(connectionHandle, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_NTS);
      // ...
      SQLDriverConnectW(connectionHandle, NULL, szConnectionString, cbConnectionString, NULL, 0, NULL, SQL_DRIVER_NOPROMPT);
      // ...
  }
  
  void runMain() {
      SQLRETURN rc;
  
      SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &amp;environmentHandle);
  
      // switch to ODBC 3.0
      SQLSetEnvAttr(environmentHandle, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
  
      // This works:
      // testConnect();
  
      // This works NOT!
      std::thread threadObj(testConnect);
      threadObj.join();
  
      // ...
  }
  
  int main() {
      try {
          runMain();
      }
      catch(...) {
          std::cout &lt;&lt; "error\n";
      }
      return 0;
  }
  </code></pre>
  
  <p>If I run this program it crashes when calling SQLSetConnectAttrW.
  Then I figured out, that it will crash already when I establish the environment if runMain is not called within the main thread.
  If I change the main function to this, then I get a segfault already by calling SQLSetEnvAttr.</p>
  
  <pre><code>int main() {
      try {
          std::thread threadObj(runMain);
          threadObj.join();
      }
      catch(...) {
          std::cout &lt;&lt; "error\n";
      }
      return 0;
  }
  </code></pre>
  
  <p>I cannot imagin if there is a bug in the oracle db driver library. But I also cannot find a bug in my code.
  Has anyone faced this issue before? Can someone help?</p>
  
  <p>Thank you!</p>
  
  <p>Regards
  Sven</p>