c++httpindyindy10c++builder-xe7

Periodic Access Violations when setting up a TIdHTTP object


I'm struggling with periodic access violations when setting up a TIdHTTP object. I'm using the following code:

TIdHTTP* httpClient = new TIdHTTP(Application->MainForm);
httpClient->HTTPOptions = (httpClient->HTTPOptions >> hoForceEncodeParams);
httpClient->HTTPOptions = (httpClient->HTTPOptions << hoKeepOrigProtocol);
httpClient->HTTPOptions = (httpClient->HTTPOptions << hoInProcessAuth);
httpClient->Request->ContentType = L"application/json";
httpClient->Request->CharSet = L"UTF-8";

TIdSSLIOHandlerSocketOpenSSL* sslIOHandler = new TIdSSLIOHandlerSocketOpenSSL;
sslIOHandler->SSLOptions->SSLVersions = TIdSSLVersions() << sslvTLSv1 << sslvTLSv1_1 << sslvTLSv1_2;

httpClient->IOHandler = sslIOHandler;

httpClient->Request->BasicAuthentication = false;
httpClient->Request->Authentication = new TIdSSPINTLMAuthentication;
httpClient->Request->Username = connectionInfo->AuthUsername;
httpClient->Request->Password = connectionInfo->AuthPassword;

// Make a request from a REST API

delete sslIOHandler;
delete httpClient;

This code runs in a thread (TThread). There could be several threads active at any given time, making seperate requests. As each request is completed, the thread is destroyed.

This code works most of the time, but after running for a seemingly random amount of time will start throwing access violations, usually in the form:

Access violation at address 5016C927 in module 'rtl210.bpl'. Read of address 00000008

Once access violations start, all subsequent threads will throw similar access violations. The only way to get things back on track is to shutdown the application and restart.

I'm using C++Builder XE7, with the version of Indy which shipped with the compiler (Indy 10.6.1.5182 ???)

So far I have been unable to replicate this problem in the debugger to get any additional information.

Any ideas what might be causing the access violation?


Solution

  • As per the comment by Remy Lebeau, the solution was to remove the owner from the TIdHTTP object:

    Change

    TIdHTTP* httpClient = new TIdHTTP(Application->MainForm);
    

    to

    TIdHTTP* httpClient = new TIdHTTP(NULL);