tinymux/mux/include/sql.h
Stephen Dennis bad69fb9aa sqlslave: fix ref-count races, buffer ownership, and MySQL build break
Address the high-priority SQLSlave issues plus a latent compile error that
only surfaces once HAVE_MYSQL is enabled:

- #745: CQueryServer/CQueryServerFactory m_cRef -> std::atomic<uint32_t>
  with fetch_add(relaxed)/fetch_sub(acq_rel), matching comsys/mail. Closes
  the decrement/zero-check double-delete race.
- #746: g_cComponents/g_cServerLocks -> std::atomic<int32_t>.
- #747: Connect() rejects null server/database/user/password rather than
  letting mysql_real_connect() and ConnectionHelper() dereference them.
- #748: copy the connection parameters into module-owned std::strings
  instead of aliasing and delete[]-ing the caller's buffers. The old code
  delete[]'d mudconf-owned storage in-process and stack buffers across the
  proxy/stub boundary (lib/libmux.cpp CQueryControlStub::Invoke).
- #764: mysql_real_query() was called with a const-stripping
  reinterpret_cast<char *> on a const UTF8 *, a hard -std=c++17 error that
  broke the build whenever a MySQL client library is present. Cast to
  const char * (the parameter type) instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 15:00:16 -06:00

32 lines
666 B
C++

/*! \file sql.h
* \brief Definitions for SQLProxy and SQLSlave Modules
*
*/
#ifndef SQL_H
#define SQL_H
#include <atomic>
class CQueryServerFactory : public mux_IClassFactory
{
public:
// mux_IUnknown
//
virtual MUX_RESULT QueryInterface(MUX_IID iid, void **ppv);
virtual uint32_t AddRef(void);
virtual uint32_t Release(void);
// mux_IClassFactory
//
virtual MUX_RESULT CreateInstance(mux_IUnknown *pUnknownOuter, MUX_IID iid, void **ppv);
virtual MUX_RESULT LockServer(bool bLock);
CQueryServerFactory(void);
virtual ~CQueryServerFactory();
private:
std::atomic<uint32_t> m_cRef;
};
#endif // SQL_H