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.