Return malloced memory from rpmcpioStrerror()

- This is unlikely to ever run into threads, but returning a const
  pointer to a static buffer is sooooo last century...
This commit is contained in:
Panu Matilainen 2013-02-19 21:55:24 +02:00
parent 8002b3f985
commit 0e0ec5bd98
4 changed files with 16 additions and 11 deletions

View File

@ -46,12 +46,13 @@ static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char * fmodeMacro)
&csa->cpioArchiveSize, &failedFile);
if (fsmrc) {
char *emsg = rpmcpioStrerror(fsmrc);
if (failedFile)
rpmlog(RPMLOG_ERR, _("create archive failed on file %s: %s\n"),
failedFile, rpmcpioStrerror(fsmrc));
failedFile, emsg);
else
rpmlog(RPMLOG_ERR, _("create archive failed: %s\n"),
rpmcpioStrerror(fsmrc));
rpmlog(RPMLOG_ERR, _("create archive failed: %s\n"), emsg);
free(emsg);
}
free(failedFile);

View File

@ -350,9 +350,9 @@ rpmcpio_t rpmcpioFree(rpmcpio_t cpio)
return NULL;
}
const char * rpmcpioStrerror(int rc)
char * rpmcpioStrerror(int rc)
{
static char msg[256];
char msg[256];
const char *s;
int myerrno = errno;
size_t l;
@ -411,5 +411,5 @@ const char * rpmcpioStrerror(int rc)
l -= strlen(s);
if (l > 0) strncat(msg, strerror(myerrno), l);
}
return msg;
return xstrdup(msg);
}

View File

@ -132,10 +132,10 @@ ssize_t rpmcpioRead(rpmcpio_t cpio, void * buf, size_t size);
/** \ingroup payload
* Return formatted error message on payload handling failure.
* @param rc error code
* @return formatted error string
* @return formatted error string (malloced)
*/
/* XXX should be RPM_GNUC_INTERNAL too but build/pack.c uses */
const char * rpmcpioStrerror(int rc);
char * rpmcpioStrerror(int rc);
#ifdef __cplusplus
}

View File

@ -835,11 +835,13 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
rpmpsmNotify(psm, RPMCALLBACK_INST_STOP, psm->total);
if (fsmrc) {
char *emsg = rpmcpioStrerror(fsmrc);
rpmlog(RPMLOG_ERR,
_("unpacking of archive failed%s%s: %s\n"),
(psm->failedFile != NULL ? _(" on file ") : ""),
(psm->failedFile != NULL ? psm->failedFile : ""),
rpmcpioStrerror(fsmrc));
emsg);
free(emsg);
rc = RPMRC_FAIL;
/* XXX notify callback on error. */
@ -939,13 +941,15 @@ static rpmRC rpmpsmStage(rpmpsm psm, pkgStage stage)
break;
case PSM_FINI:
if (rc) {
char *emsg = rpmcpioStrerror(rc);
if (psm->failedFile)
rpmlog(RPMLOG_ERR,
_("%s failed on file %s: %s\n"),
psm->goalName, psm->failedFile, rpmcpioStrerror(rc));
psm->goalName, psm->failedFile, emsg);
else
rpmlog(RPMLOG_ERR, _("%s failed: %s\n"),
psm->goalName, rpmcpioStrerror(rc));
psm->goalName, emsg);
free(emsg);
/* XXX notify callback on error. */
rpmtsNotify(ts, psm->te, RPMCALLBACK_CPIO_ERROR, 0, 0);