简体   繁体   English

设置TIdHTTP对象时出现定期访问冲突

[英]Periodic Access Violations when setting up a TIdHTTP object

I'm struggling with periodic access violations when setting up a TIdHTTP object. 在设置TIdHTTP对象时,我正在努力解决周期性访问冲突问题。 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). 此代码在线程(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 ???) 我正在使用C ++ Builder XE7,随编译器附带的Indy版本(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? 可能导致访问违规的任何想法?

As per the comment by Remy Lebeau, the solution was to remove the owner from the TIdHTTP object: 根据Remy Lebeau的评论,解决方案是从TIdHTTP对象中删除所有者:

Change 更改

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

to

TIdHTTP* httpClient = new TIdHTTP(NULL);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM