rem: close(sock);
context: Ns_FetchURL(Ns_DString *dsPtr, char *url, Ns_Set *headers){    int  	    sock;    char    	   *p;    Ns_DString      ds;    Stream  	    stream;    Ns_Request     *request;    int     	    status, tosend, n;    status = NS_ERROR;        sock = -1;    Ns_DStringInit(&ds);    /*     * Parse the URL and open a connection.     */    Ns_DStringVarAppend(&ds, "GET ", url, " HTTP/1.0", NULL);    request = Ns_ParseRequest(ds.string);    if (request == NULL || request->protocol == NULL ||	!STREQ(request->protocol, "http") || request->host == NULL) {        Ns_Log(Notice, "urlopen: invalid url '%s'", url);        goto done;    }    if (request->port == 0) {        request->port = 80;    }    sock = Ns_SockConnect(request->host, request->port);        if (sock == -1) {	Ns_Log(Error, "urlopen: failed to connect to '%s': '%s'",	       url, strerror(errno));	goto done;    }    /*     * Send a simple HTTP GET request.     */         Ns_DStringTrunc(&ds, 0);    Ns_DStringVarAppend(&ds, "GET ", request->url, NULL);    if (request->query != NULL) {        Ns_DStringVarAppend(&ds, "?", request->query, NULL);    }    Ns_DStringAppend(&ds, " HTTP/1.0\r\nAccept: */*\r\n\r\n");    p = ds.string;    tosend = ds.length;    while (tosend > 0) {        n = send(sock, p, tosend, 0);        if (n == -1) {            Ns_Log(Error, "urlopen: failed to send data to '%s': '%s'",		   url, strerror(errno));	    close(sock);            goto done;        }        tosend -= n;	p += n;    }    /*     * Buffer the socket and read the response line and then     * consume the headers, parsing them into any given header set.     */    stream.cnt = 0;    stream.error = 0;    stream.ptr = stream.buf;    stream.sock = sock;    if (!GetLine(&stream, &ds)) {	goto done;    }    if (headers != NULL && strncmp(ds.string, "HTTP", 4) == 0) {	if (headers->name != NULL) {	    ns_free(headers->name);	}	headers->name = Ns_DStringExport(&ds);    }    do {	if (!GetLine(&stream, &ds)) {	    goto done;	}	if (ds.length > 0	    && headers != NULL	    && Ns_ParseHeader(headers, ds.string, Preserve) != NS_OK) {	    goto done;	}    } while (ds.length > 0);    /*     * Without any check on limit or total size, foolishly read     * the remaining content into the dstring.     */    do {    	Ns_DStringNAppend(dsPtr, stream.ptr, stream.cnt);    } while (FillBuf(&stream));    if (!stream.error) {    	status = NS_OK;    }     done:    if (request != NULL) {        Ns_FreeRequest(request);    }    if (sock != -1) {        close(sock);    }    Ns_DStringFree(&ds);    return status;}