From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MqMu3-0000br-9E for mharc-grub-devel@gnu.org; Wed, 23 Sep 2009 04:08:43 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MqMu1-0000bm-HL for grub-devel@gnu.org; Wed, 23 Sep 2009 04:08:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MqMtx-0000ba-QA for grub-devel@gnu.org; Wed, 23 Sep 2009 04:08:41 -0400 Received: from [199.232.76.173] (port=59856 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MqMtx-0000bX-Me for grub-devel@gnu.org; Wed, 23 Sep 2009 04:08:37 -0400 Received: from mx20.gnu.org ([199.232.41.8]:2762) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MqMtx-00022u-4p for grub-devel@gnu.org; Wed, 23 Sep 2009 04:08:37 -0400 Received: from posti7.jyu.fi ([130.234.4.44]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MqMtt-00026P-C7 for grub-devel@gnu.org; Wed, 23 Sep 2009 04:08:33 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by posti7.jyu.fi (8.13.8/8.13.8) with ESMTP id n8N88TWi004997; Wed, 23 Sep 2009 11:08:29 +0300 X-Virus-Scanned: amavisd-new at cc.jyu.fi Received: from posti7.jyu.fi ([127.0.0.1]) by localhost (posti7.jyu.fi [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I1iV8wpVjxIS; Wed, 23 Sep 2009 11:08:26 +0300 (EEST) Received: from [130.234.78.125] (semyol-329-b.ktl.jyu.fi [130.234.78.125]) (authenticated bits=0) by posti7.jyu.fi (8.13.8/8.13.8) with ESMTP id n8N88PqX004992; Wed, 23 Sep 2009 11:08:26 +0300 Message-ID: <4AB9D76C.5040307@peda.net> Date: Wed, 23 Sep 2009 11:08:12 +0300 From: Mikko Rantalainen User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: The development of GRUB 2 References: In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigD8357ECD0E4D31B18466370D" X-detected-operating-system: by mx20.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Subject: Re: [PATCH]: Save boot record before writing to the dest_drive X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Sep 2009 08:08:41 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigD8357ECD0E4D31B18466370D Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable kashyap garimella wrote at 2009-09-12: > Greetings! >=20 > I have added the following new features: >=20 > 1) when grub-setup runs, it automatically stores the areas of (mbr + em= bed) > region, which are overwritten, into the file (in the following specifie= d > format) in root directory. >=20 > 2) grub-setup can restore the stored mbr in the following format back t= o > destination drive: > [...] >=20 > PROBLEMS: > A warning: > util/i386/pc/grub-setup.c:93: warning: =91backup_img=92 may be used > uninitialized in this function > When I remove the line (496 in the patched one): free(backup_img); > the warning goes off. > I could not understand how to resolve it. I need some help I looked at the patch and it seems that the problem could be caused by following code: > + if (!backup_fp) > + { > + strcpy(grub_errmsg,"Unable to create the backup file"); > + goto unable_to_save; > + } > + > + /* 8 bytes for embed_region.start, another 8 for core_size */ > + int backup_img_size =3D core_size + GRUB_DISK_SECTOR_SIZE + 8 + 8 = + 1 /* seperation byte 0xff */ ; > + backup_img =3D (char *) xmalloc (backup_img_size); =2E.. > +save_finish: =20 > + fclose (backup_fp); > + free(backup_path); > + free(backup_img); Notice that you're using "goto" to skip initialization of backup_img and you blindly free()ing it in "save_finish". I think a nice way to fix this (if you want to use "goto") is to use multiple clean up labels. Like this: +save_cleanup_backup_img: + free(backup_img); +save_cleanup_backup_fp: + fclose (backup_fp); +save_cleanup_backup_path: + free(backup_path); Note that you should release the resources in reverse order compared to the order of acquiring the resources. If you need to bail out after you have acquired the backup_fp but have not yet acquired the backup_img, use "goto save_cleanup_backup_fp". --=20 Mikko --------------enigD8357ECD0E4D31B18466370D Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkq513kACgkQFNzRB1YxaOt3lACeOP7wp9rYhzZCbhC1GlVOVUmr t/QAoJSwqDVJqXsRlxsjd0GgczA02qT+ =2Vi/ -----END PGP SIGNATURE----- --------------enigD8357ECD0E4D31B18466370D--