Fix warnings: hardcopy.c: mch_print_text_out(): Bad free: FP + RI.

Problem    : Bad free @ 3058.
Diagnostic : False positive uncovering a real issue.
Rationale  : Signaled error occurs if p gets assigned `(char_u*)""` at
             line 3009 and then is freed at line 3058. But that cannot
             happen because of the last guard condition before `free`
             (`*p != NUL`). So, signaled error is a false positive.
             Now, examining this code more carefully reveals a real
             issue: not freeing an empty string may not be always
             correct, as an empty (but allocated) string could also be
             returned in `p = string_convert(&prt_conv, p, &len);` if
             passed '&len' points to 0). Which would in fact be a memory
             leak.
Resolution : Remove the exceptional case. Make p always point to
             allocated memory, and always free it, when `prt_do_conv` is
             on.
This commit is contained in:
Eliseo Martínez 2014-11-10 11:18:27 +01:00
parent 6d057a2ca5
commit 51080737df

View File

@ -3006,7 +3006,7 @@ int mch_print_text_out(char_u *p, int len)
/* Convert from multi-byte to 8-bit encoding */
p = string_convert(&prt_conv, p, &len);
if (p == NULL)
p = (char_u *)"";
p = (char_u *)xstrdup("");
}
if (prt_out_mbyte) {
@ -3054,7 +3054,7 @@ int mch_print_text_out(char_u *p, int len)
}
/* Need to free any translated characters */
if (prt_do_conv && (*p != NUL))
if (prt_do_conv)
free(p);
prt_text_run += char_width;