rem: ns_free(copy);
add: if (copy) { ns_free(copy); }
context: Ns_DecodeUrlWithEncoding(Ns_DString *dsPtr, char *string, Tcl_Encoding encoding){    register int i, j, n;    register char *p, *q;    char         *copy;    int           length;    Tcl_DString   ds;    /*     * Copy the decoded characters directly to the dstring,     * unless we need to do encoding.     */    length = strlen(string);    if (encoding != NULL) {        copy = ns_malloc((size_t)(length+1));        q = copy;    } else {        /*         * Expand the dstring to the length of the input         * string which will be the largest size required.         */        i = dsPtr->length;        Ns_DStringSetLength(dsPtr, i + length);        q = dsPtr->string + i;    }    p = string;    n = 0;    while (UCHAR(*p) != '\0') {	if (UCHAR(p[0]) == '%' &&	    (i = enc[UCHAR(p[1])].hex) >= 0 &&	    (j = enc[UCHAR(p[2])].hex) >= 0) {	    *q++ = (unsigned char) ((i << 4) + j);	    p += 3;	} else if (UCHAR(*p) == '+') {	    *q++ = ' ';	    ++p;	} else {	    *q++ = *p++;	}	++n;    }    /* Ensure our new string is terminated */    *q = '\0';    if (encoding != NULL) {        Tcl_ExternalToUtfDString(encoding, copy, n, &ds);        Ns_DStringAppend(dsPtr, Tcl_DStringValue(&ds));        Tcl_DStringFree(&ds);        ns_free(copy);    } else {        /*         * Set the dstring length to the actual size required.         */        Ns_DStringSetLength(dsPtr, n);    }    return dsPtr->string;}