From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id E1E7E3858430; Sat, 9 Jul 2022 05:59:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1E7E3858430 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Fix an issue which causes when realloc() fails. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 282d57d2a8462c56ceeafcc10095cab35343eb09 X-Git-Newrev: 421dcf72fb02bda019e311dbe18a41b9bc9cd56b Message-Id: <20220709055905.E1E7E3858430@sourceware.org> Date: Sat, 9 Jul 2022 05:59:05 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jul 2022 05:59:06 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D421dcf72fb0= 2bda019e311dbe18a41b9bc9cd56b commit 421dcf72fb02bda019e311dbe18a41b9bc9cd56b Author: Takashi Yano Date: Sat Jul 9 14:16:11 2022 +0900 Cygwin: console: Fix an issue which causes when realloc() fails. Diff: --- winsup/cygwin/fhandler_console.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_con= sole.cc index 47d30bc88..c542fa46e 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -296,7 +296,11 @@ fhandler_console::cons_master_thread (handle_set_t *p,= tty *ttyp) (INPUT_RECORD *) malloc (inrec_size * sizeof (INPUT_RECORD)); =20 if (!input_rec || !input_tmp) - return; /* Cannot continue */ + { /* Cannot continue */ + free (input_rec); + free (input_tmp); + return; + } =20 DWORD inrec_size1 =3D wincap.cons_need_small_input_record_buf () ? INREC_SIZE : inrec_size; @@ -343,13 +347,15 @@ fhandler_console::cons_master_thread (handle_set_t *p= , tty *ttyp) DWORD new_inrec_size =3D total_read + additional_space; INPUT_RECORD *new_input_rec =3D (INPUT_RECORD *) realloc (input_rec, m::bytes (new_inrec_size)); + if (new_input_rec) + input_rec =3D new_input_rec; INPUT_RECORD *new_input_tmp =3D (INPUT_RECORD *) realloc (input_tmp, m::bytes (new_inrec_size)); + if (new_input_tmp) + input_tmp =3D new_input_tmp; if (new_input_rec && new_input_tmp) { inrec_size =3D new_inrec_size; - input_rec =3D new_input_rec; - input_tmp =3D new_input_tmp; if (!wincap.cons_need_small_input_record_buf ()) inrec_size1 =3D inrec_size; } @@ -478,13 +484,15 @@ remove_record: DWORD new_inrec_size =3D n + additional_space; INPUT_RECORD *new_input_rec =3D (INPUT_RECORD *) realloc (input_rec, m::bytes (new_inrec_size)); + if (new_input_rec) + input_rec =3D new_input_rec; INPUT_RECORD *new_input_tmp =3D (INPUT_RECORD *) realloc (input_tmp, m::bytes (new_inrec_size)); + if (new_input_tmp) + input_tmp =3D new_input_tmp; if (new_input_rec && new_input_tmp) { inrec_size =3D new_inrec_size; - input_rec =3D new_input_rec; - input_tmp =3D new_input_tmp; if (!wincap.cons_need_small_input_record_buf ()) inrec_size1 =3D inrec_size; }