Skip to content
Tcl Source Code Artifact [7c4aa22bf6]
Login

Artifact [7c4aa22bf6]

Artifact 7c4aa22bf616237145de6c5d39493c57a32837bf:

Ticket change [7c4aa22bf6] - Ticket [6ca52aec14e0b335|6ca52aec14] <i>HTTP package: Memory leak if client requests &quot;Connection: close&quot; but server responses with &quot;Connection: keep-alive&quot;</i> status still Open with 3 other changes by anonymous on 2015-07-20 15:37:36.
D 2015-07-20T15:37:36.531
J comment Hello,\r\nThe\s'geturl'\scommand\sof\sthe\s'http'\spackage\sdoes\snot\sfree\sup\sproperly\sthe\sused\svariables\sif\sgeturl\sif\sa\sGET\srequest\sis\smade\sand\sthe\s'-keepalive'\soption\sis\snot\sused\s('Connection:\sclose'\sis\stransmitted),\sbut\sif\sthe\sserver\sresponses\s(by\smistake)\swith\s'Connection:\skeep-alive'.\r\n\r\nAfter\srunning\s10\stimes\s...\r\n\r\n\s\s\sset\sHandle\s[::http::geturl\s"http://localhost:8080/c"]\r\n\s\s\sputs\s"$k:\\n\s\sHandle:$Handle\\n\s\sStatus:\s[::http::status\s$Handle]\\n\s\sData:\s[http::data\s$Handle]"\r\n\s\s\s::http::cleanup\s$Handle\r\n\r\n...\sand\shaving\sthe\sserver\sresponding\swith\s'Connection:\skeep-alive'\sthe\sfollowing\svariables\swill\sbe\sdefined\sin\sthe\shttp\snamespace\s(info\svars\shttp::*):\r\n\r\n\s\s\s::http::http\s::http::urlTypes\s::http::1\s::http::encodings\s::http::2\s::http::3\s::http::4\s::http::5\s::http::6\s::http::7\s::http::8\s::http::9\s::http::strict\s::http::formMap\s::http::defaultKeepalive\s::http::socketmap\s::http::defaultCharset\r\n\r\nThe\svariables\s1..9\sare\sthe\stemporary\svariables\sthat\sshould\sbe\sdeleted\swith\sthe\s'http::cleanup'\scommand.\r\n\r\nBelow\sthere\sis\sa\stest\scase\scomposed\sby\s2\sparts\s(files):\r\n\r\n*\sHTTP\sserver:\sIt\sopens\sand\slistens\sthe\slocal\sport\s8080.\sIt\saccepts\s3\srequests\s(http://localhost:8080/a,\shttp://localhost:8080/b,\shttp://localhost:8080/c)\sthat\sare\sresponded\sin\s3\sdifferent\sways:\sRequest\s'a'\swill\snot\sreturn\sany\s'Connection'\sattribute,\srequest\s'b'\swill\sreturn\s'Connection:\sclose',\sand\srequest\s'c'\swill\sreturn\s'Connection:\skeep-alive'.\r\n*\sHTTP\sclient:\sIt\sperforms\sfor\seach\sof\sthe\s3\srequests\saccepted\sby\sthe\sHTTP\sserver\s10\srequests.\sAfter\seach\srequest\sthe\svariables\sin\sthe\s'http'\snamespace\sare\sprinted.\r\n\r\n-------------------------\sFile\s'Run\sMemoryLeak_TestCase_Server.tcl'\s-------------------------\r\n\r\nnamespace\seval\sHttpServer\s{\r\n\tproc\sStart\s{port}\s{\r\n\t\tputs\s"HttpServer::Start\s$port"\r\n\t\tset\sServer\s[socket\s-server\s[namespace\scurrent]::Accept\s$port]\r\n\t}\r\n\r\n\tproc\sAccept\s{sock\shost\sport}\s{\r\n\t\tputs\s"HttpServer::Accept\s$sock\s$host\s$port"\r\n\t\tfconfigure\s$sock\s-blocking\s0\s-buffering\snone\r\n\t\tfileevent\s$sock\sreadable\s[list\s[namespace\scurrent]::Handle\s$sock]\r\n\t}\r\n\r\n\tproc\sHandle\s{Socket}\s{\r\n\t\tputs\s"HttpServer::Handle\s$Socket"\r\n\t\tif\s{[eof\s$Socket]}\s{\r\n\t\t\tputs\s"\s\seof->close\ssocket"\r\n\t\t\tclose\s$Socket\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tputs\s"\s\sRead\sdata"\r\n\t\tset\sData\s[read\s$Socket]\r\n\t\tregexp\s-line\s{^(.*)$}\s$Data\s{}\sFirstLine\r\n\t\tregsub\s-all\s-line\s{^}\s$Data\s{\s\s\s->\s}\sData\r\n\t\tputs\s$Data\r\n\r\n\t\tif\s{[regexp\s{GET\s/(.*)\sHTTP/1.1}\s$FirstLine\s{}\sGetArgs]}\s{\r\n\t\t\tputs\s"\s\sGetArgs:$GetArgs"\r\n\t\t\tputs\s"\s\sReturn\sdata"\r\n\t\t\tif\s{$GetArgs=="a"}\s{\r\n\t\t\t\tputs\s$Socket\s"HTTP/1.1\s200\sOK"\r\n\t\t\t\tputs\s$Socket\s"Content-length:\s31"\r\n\t\t\t\tputs\s$Socket\s""\r\n\t\t\t\tputs\s$Socket\s"Data\sreceived\son\s[clock\sseconds]\s-\sa"\r\n\t\t\t}\selseif\s{$GetArgs=="b"}\s{\r\n\t\t\t\tputs\s$Socket\s"HTTP/1.1\s200\sOK"\r\n\t\t\t\tputs\s$Socket\s"Content-length:\s31"\r\n\t\t\t\tputs\s$Socket\s"Connection:\sclose"\r\n\t\t\t\tputs\s$Socket\s""\r\n\t\t\t\tputs\s$Socket\s"Data\sreceived\son\s[clock\sseconds]\s-\sb"\r\n\t\t\t}\selseif\s{$GetArgs=="c"}\s{\r\n\t\t\t\tputs\s$Socket\s"HTTP/1.1\s200\sOK"\r\n\t\t\t\tputs\s$Socket\s"Content-length:\s31"\r\n\t\t\t\tputs\s$Socket\s"Connection:\skeep-alive"\r\n\t\t\t\tputs\s$Socket\s""\r\n\t\t\t\tputs\s$Socket\s"Data\sreceived\son\s[clock\sseconds]\s-\sc"\r\n\t\t\t}\selse\s{\r\n\t\t\t\tputs\s$Socket\s"HTTP/1.1\s404\snot\sfound"\r\n\t\t\t\tputs\s$Socket\s""\r\n\t\t\t\tputs\s$Socket\s"<html><h1>404\s-\sNot\sfound\s'$GetArgs'</h1></html>"\r\n\t\t\t}\r\n\t\t}\selse\s{\r\n\t\t\tputs\s$Socket\s"HTTP/1.1\s400\sbad\srequest"\r\n\t\t\tputs\s$Socket\s""\r\n\t\t\tputs\s$Socket\s"<html><h1>400\s-\sBad\srequest</h1></html>"\r\n\t\t}\r\n\r\n\t\tputs\s"\s\sClose\ssocket\s$Socket"\r\n\t\tclose\s$Socket\r\n\t}\r\n};\s#\send\snamespace\sHttpServer\r\n\r\nHttpServer::Start\s8080\r\n\r\n-------------------------\sFile\s'Run\sMemoryLeak_TestCase_Client.tcl'\s-------------------------\r\n\r\npackage\srequire\shttp\r\n#\ssource\s./http-2.8.5.tm\r\n\r\nproc\sListVarHttp\s{}\s{\r\n\tputs\s"HttpVars([llength\s[info\svars\shttp::*]]):\s[info\svars\shttp::*]"\r\n}\r\n\r\nListVarHttp\r\n\r\nputs\s"GetUrl\shttp://localhost:8080/a"\r\nfor\s{set\sk\s0}\s{$k<10}\s{incr\sk}\s{\r\n\tset\sHandle\s[::http::geturl\s"http://localhost:8080/a"]\r\n\tputs\s"$k:\\n\s\sHandle:$Handle\\n\s\sStatus:\s[::http::status\s$Handle]\\n\s\sData:\s[http::data\s$Handle]"\r\n\t::http::cleanup\s$Handle\r\n\r\n\tListVarHttp\r\n}\r\n\r\nputs\s"GetUrl\shttp://localhost:8080/b"\r\nfor\s{set\sk\s0}\s{$k<10}\s{incr\sk}\s{\r\n\tset\sHandle\s[::http::geturl\s"http://localhost:8080/b"]\r\n\tputs\s"$k:\\n\s\sHandle:$Handle\\n\s\sStatus:\s[::http::status\s$Handle]\\n\s\sData:\s[http::data\s$Handle]"\r\n\t::http::cleanup\s$Handle\r\n\r\n\tListVarHttp\r\n}\r\n\r\nputs\s"GetUrl\shttp://localhost:8080/c"\r\nfor\s{set\sk\s0}\s{$k<10}\s{incr\sk}\s{\r\n\tset\sHandle\s[::http::geturl\s"http://localhost:8080/c"]\r\n\tputs\s"$k:\\n\s\sHandle:$Handle\\n\s\sStatus:\s[::http::status\s$Handle]\\n\s\sData:\s[http::data\s$Handle]"\r\n\t::http::cleanup\s$Handle\r\n\r\n\tListVarHttp\r\n}
J login anonymous
J mimetype text/plain
K 6ca52aec14e0b33543d3cd9895f060b852ac4dbc
U anonymous
Z 86e5136d1239f714b4075497b91c8a8b