title: How to correctly instantiate RestTemplate without leaking resources
body: <p>Please I have the following bean definitions</p>
  
  <pre><code> @Bean
      public RestTemplate produceRestTemplate(ClientHttpRequestFactory requestFactory){
          RestTemplate restTemplate = new RestTemplate(requestFactory);
          restTemplate.setErrorHandler(restTemplateErrorHandler);
          return restTemplate;
      }
  
  @Bean
  public ClientHttpRequestFactory createRequestFactory() {
      PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
      connectionManager.setMaxTotal(maxTotalConn);
      connectionManager.setDefaultMaxPerRoute(maxPerChannel);
  
      RequestConfig config = RequestConfig.custom().setConnectTimeout(100000).build();
      CloseableHttpClient httpClient = HttpClients.createDefault();
      return new HttpComponentsClientHttpRequestFactory(httpClient);
  }
  </code></pre>
  
  <p>The code works well but the problem is that fortify flags the code above as being potentially problematic with the following </p>
  
  <blockquote>
    <p>"The function createRequestFactory() sometimes
    fails to release a socket allocated by createDefault() on line 141."</p>
  </blockquote>
  
  <p>Please anyone with any ideas as to how to correctly do this without fortify raising alarms</p>
  
  <p>Thanks in advance</p>