From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 667153858430; Sat, 9 Jul 2022 05:59:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 667153858430 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-3_3-branch] 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/cygwin-3_3-branch X-Git-Oldrev: 521dfff143f9533533d161f37b73a92147c88e7c X-Git-Newrev: befaafc9ed6502b54ba1f35841b044950c6230a3 Message-Id: <20220709055928.667153858430@sourceware.org> Date: Sat, 9 Jul 2022 05:59:28 +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:28 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dbefaafc9ed6= 502b54ba1f35841b044950c6230a3 commit befaafc9ed6502b54ba1f35841b044950c6230a3 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 c50bb95a5..e080fd6c8 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; } @@ -477,13 +483,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; }