+
Skip to content

Allocate msg only after fatal checks to avoid leaks #1998

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions builtin/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,25 +308,25 @@ static int parse_file_arg(const struct option *opt, const char *arg, int unset)
static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
{
struct note_data *d = opt->value;
struct note_msg *msg = xmalloc(sizeof(*msg));
struct note_msg *msg;
char *value;
struct object_id object;
enum object_type type;
unsigned long len;

BUG_ON_OPT_NEG(unset);

strbuf_init(&msg->buf, 0);
if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
if (!(value = repo_read_object_file(the_repository, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
strbuf_release(&msg->buf);
free(value);
free(msg);
die(_("cannot read note data from non-blob object '%s'."), arg);
}
if (type != OBJ_BLOB) {
free(value);
die(_("cannot read note data from non-blob object '%s'."), arg);
}

msg = xmalloc(sizeof(*msg));
strbuf_init(&msg->buf, 0);

strbuf_add(&msg->buf, value, len);
free(value);
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载