Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential memory leak in vnc_clip.c #3387

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions vnc/vnc_clip.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ static int
handle_cb_format_data_request(struct vnc *v, struct stream *s)
{
int format = 0;
struct stream *out_s;
struct stream *out_s = NULL;
int i;
struct vnc_clipboard_data *vc = v->vc;
int rv = 0;
Expand All @@ -416,7 +416,6 @@ handle_cb_format_data_request(struct vnc *v, struct stream *s)
LOG_DEVEL(LOG_LEVEL_INFO, "RDP client requested data format=%s",
cf2text(format, scratch, sizeof(scratch)));

make_stream(out_s);

/* For all formats, we need to convert to Windows carriage control,
* so we need to know how many '\n' characters become '\r\n' */
Expand Down Expand Up @@ -448,8 +447,11 @@ handle_cb_format_data_request(struct vnc *v, struct stream *s)

/* Allocate the stream and check for failure as the string could be
* essentially unlimited in length */
init_stream(out_s, alloclen);
if (out_s->data == NULL)
if ((make_stream(out_s)) != NULL)
{
init_stream(out_s, alloclen);
}
if (out_s == NULL || out_s->data == NULL)
{
LOG(LOG_LEVEL_ERROR,
"Memory exhausted allocating %d bytes for clip data response",
Expand Down Expand Up @@ -512,8 +514,8 @@ handle_cb_format_data_request(struct vnc *v, struct stream *s)

s_mark_end(out_s);
send_stream_to_clip_channel(v, out_s);
free_stream(out_s);
}
free_stream(out_s);

return rv;
}
Expand Down
Loading