From: Panu Matilainen Date: Thu, 7 Jul 2011 08:17:29 +0000 (+0300) Subject: Only bother mallocing lead for return if read actually succeeded X-Git-Tag: rpm-4.10.0-beta1~394 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e156eac1c8d1703d311277d177ddc0ebba9b187a;p=platform%2Fupstream%2Frpm.git Only bother mallocing lead for return if read actually succeeded - Doesn't make much of a difference now, just paving way for next steps --- diff --git a/lib/rpmlead.c b/lib/rpmlead.c index 6ad2c37..ad47722 100644 --- a/lib/rpmlead.c +++ b/lib/rpmlead.c @@ -113,9 +113,10 @@ rpmRC rpmLeadCheck(rpmlead lead, const char **msg) rpmRC rpmLeadRead(FD_t fd, rpmlead *lead) { rpmRC rc = RPMRC_OK; - rpmlead l = xcalloc(1, sizeof(*l)); + struct rpmlead_s l; - if (Fread(l, 1, sizeof(*l), fd) != sizeof(*l)) { + memset(&l, 0, sizeof(l)); + if (Fread(&l, 1, sizeof(l), fd) != sizeof(l)) { if (Ferror(fd)) { rpmlog(RPMLOG_ERR, _("read failed: %s (%d)\n"), Fstrerror(fd), errno); @@ -124,20 +125,18 @@ rpmRC rpmLeadRead(FD_t fd, rpmlead *lead) rpmlog(RPMLOG_ERR, _("not an rpm package\n")); rc = RPMRC_NOTFOUND; } + } else { + l.type = ntohs(l.type); + l.archnum = ntohs(l.archnum); + l.osnum = ntohs(l.osnum); + l.signature_type = ntohs(l.signature_type); } - if (rc == RPMRC_OK) { - l->type = ntohs(l->type); - l->archnum = ntohs(l->archnum); - l->osnum = ntohs(l->osnum); - l->signature_type = ntohs(l->signature_type); + if (lead != NULL && rc == RPMRC_OK) { + *lead = xmalloc(sizeof(l)); + memcpy(*lead, &l, sizeof(l)); } - if (rc || lead == NULL) - rpmLeadFree(l); - else - *lead = l; - return rc; }