From: Mikko Rantalainen <mikko.rantalainen@peda.net>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH]: Save boot record before writing to the dest_drive
Date: Wed, 23 Sep 2009 11:08:12 +0300 [thread overview]
Message-ID: <4AB9D76C.5040307@peda.net> (raw)
In-Reply-To: <c202cdf80909120705u58aff93x7215a2eb5252b044@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1902 bytes --]
kashyap garimella wrote at 2009-09-12:
> Greetings!
>
> I have added the following new features:
>
> 1) when grub-setup runs, it automatically stores the areas of (mbr + embed)
> region, which are overwritten, into the file (in the following specified
> format) in root directory.
>
> 2) grub-setup can restore the stored mbr in the following format back to
> destination drive:
> [...]
>
> PROBLEMS:
> A warning:
> util/i386/pc/grub-setup.c:93: warning: ‘backup_img’ 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 = core_size + GRUB_DISK_SECTOR_SIZE + 8 + 8 + 1 /* seperation byte 0xff */ ;
> + backup_img = (char *) xmalloc (backup_img_size);
...
> +save_finish:
> + 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".
--
Mikko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2009-09-23 8:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-12 14:05 [PATCH]: Save boot record before writing to the dest_drive kashyap garimella
2009-09-14 15:35 ` Robert Millan
2009-09-14 15:44 ` kashyap garimella
2009-09-19 21:10 ` Robert Millan
2009-09-19 22:09 ` Colin Watson
2009-09-20 6:50 ` richardvoigt
2009-09-20 11:22 ` Robert Millan
2009-09-23 8:08 ` Mikko Rantalainen [this message]
2009-09-24 15:45 ` kashyap garimella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AB9D76C.5040307@peda.net \
--to=mikko.rantalainen@peda.net \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.