--- /dev/null
+Description: close the file handle in time in case -file option is used
+Origin: https://www.androwish.org/index.html/vpatch?from=9afc8918cdeec6d7&to=e4864fde820aac71
+Author: Christian Werner <chw@ch-werner.de>
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=801734
+Forwarded: yes, email
+
+Index: b/generic/tclcurl.c
+===================================================================
+--- a/generic/tclcurl.c
++++ b/generic/tclcurl.c
+@@ -465,6 +465,12 @@ curlSetOpts(Tcl_Interp *interp, struct c
+ case 1:
+ Tcl_Free(curlData->outFile);
+ curlData->outFile=curlstrdup(Tcl_GetString(objv));
++ if (curlData->outFlag) {
++ if (curlData->outHandle!=NULL) {
++ fclose(curlData->outHandle);
++ curlData->outHandle=NULL;
++ }
++ }
+ if ((strcmp(curlData->outFile,""))&&(strcmp(curlData->outFile,"stdout"))) {
+ curlData->outFlag=1;
+ } else {
+@@ -1043,6 +1049,14 @@ curlSetOpts(Tcl_Interp *interp, struct c
+ case 62:
+ Tcl_Free(curlData->bodyVarName);
+ curlData->bodyVarName=curlstrdup(Tcl_GetString(objv));
++ if (curlData->outFlag) {
++ if (curlData->outHandle!=NULL) {
++ fclose(curlData->outHandle);
++ curlData->outHandle=NULL;
++ }
++ curl_easy_setopt(curlHandle,CURLOPT_WRITEDATA,NULL);
++ }
++ curlData->outFlag=0;
+ if (curl_easy_setopt(curlHandle,CURLOPT_WRITEFUNCTION,
+ curlBodyReader)) {
+ return TCL_ERROR;
+@@ -1080,6 +1094,13 @@ curlSetOpts(Tcl_Interp *interp, struct c
+ break;
+ case 65:
+ curlData->writeProc=curlstrdup(Tcl_GetString(objv));
++ if (curlData->outFlag) {
++ if (curlData->outHandle!=NULL) {
++ fclose(curlData->outHandle);
++ curlData->outHandle=NULL;
++ }
++ curl_easy_setopt(curlHandle,CURLOPT_WRITEDATA,NULL);
++ }
+ curlData->outFlag=0;
+ if (curl_easy_setopt(curlHandle,CURLOPT_WRITEFUNCTION,
+ curlWriteProcInvoke)) {