[Rd] Crash when reusing libcurl connection

Jeroen Ooms jeroen.ooms at stat.ucla.edu
Sat Jan 2 19:57:31 CET 2016


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.



More information about the R-devel mailing list