mirror of
https://github.com/neovim/neovim.git
synced 2025-10-18 15:51:50 +00:00
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:
@@ -3006,7 +3006,7 @@ int mch_print_text_out(char_u *p, int len)
|
|||||||
/* Convert from multi-byte to 8-bit encoding */
|
/* Convert from multi-byte to 8-bit encoding */
|
||||||
p = string_convert(&prt_conv, p, &len);
|
p = string_convert(&prt_conv, p, &len);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
p = (char_u *)"";
|
p = (char_u *)xstrdup("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prt_out_mbyte) {
|
if (prt_out_mbyte) {
|
||||||
@@ -3054,7 +3054,7 @@ int mch_print_text_out(char_u *p, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Need to free any translated characters */
|
/* Need to free any translated characters */
|
||||||
if (prt_do_conv && (*p != NUL))
|
if (prt_do_conv)
|
||||||
free(p);
|
free(p);
|
||||||
|
|
||||||
prt_text_run += char_width;
|
prt_text_run += char_width;
|
||||||
|
Reference in New Issue
Block a user