From jeroen.ooms at stat.ucla.edu  Sat Jan  2 19:57:31 2016
From: jeroen.ooms at stat.ucla.edu (Jeroen Ooms)
Date: Sat, 2 Jan 2016 19:57:31 +0100
Subject: [Rd] Crash when reusing libcurl connection
Message-ID: <CABFfbXuyXhzf6tceOt8VmtZRiKbT6D_fGNK9602Xdzk6-MY3Og@mail.gmail.com>

Reusing a libcurl based url() connection can lead to a crash:

  con <- url("http://httpbin.org/get", method = "libcurl")
  readLines(con)
  readLines(con)
  readLines(con)

The problem does not appear for other url() implementations:

  con <- url("http://httpbin.org/get", method = "internal")
  readLines(con)
  readLines(con)

  con <- curl::curl("http://httpbin.org/get")
  readLines(con)
  readLines(con)

>From the internet/libcurl.c source code it looks like the free() calls
should be moved out of Curl_close() and into the destroy callback
(which is currently undefined?). Comments from Connections.h suggest
that the close callback should reset, but not destroy the connection
so that it can be recycled:

  void (*close)(struct Rconn *); /* routine closing after auto open */
  void (*destroy)(struct Rconn *); /* when closing connection */

The 'curl' package has a working example how to achieve this with libcurl.



[Rd] Crash when reusing libcurl connection
Jeroen Ooms