From a2d68d1ea3afa974f7038ab1cc434fd9551d1334 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 7 Jul 2011 22:51:29 +0300 Subject: [PATCH] If we need a FILE stream then get one... - Replace the hysterical "lets see if the temp creation gave an fpio fd (it didn't), if not open another fd and then get its private FILE pointer" fiddling: since we need a FILE stream then open one with fdopen(), duh. Grabbing a rpmio fd to begin with is stupid enough when all we want is a stream, but wanting to use rpmMkTempFile() functionality... - Also fixes an fd+mem leak in the unlikely but possible case that rpmMkTempFile() succeeds but fdopen() fails. --- build/build.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/build/build.c b/build/build.c index 043760b..04b039c 100644 --- a/build/build.c +++ b/build/build.c @@ -65,8 +65,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, const char **argv = NULL; FILE * fp = NULL; - FD_t fd; - FD_t xfd; + FD_t fd = NULL; pid_t pid; pid_t child; int status; @@ -117,18 +116,14 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, } fd = rpmMkTempFile(spec->rootDir, &scriptName); - if (fd == NULL || Ferror(fd)) { - rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n")); + if (Ferror(fd)) { + rpmlog(RPMLOG_ERR, _("Unable to open temp file: %s\n"), Fstrerror(fd)); rc = RPMRC_FAIL; goto exit; } - if (fdGetFILE(fd) == NULL) - xfd = Fdopen(fd, "w.fpio"); - else - xfd = fd; - - if ((fp = fdGetFILE(xfd)) == NULL) { + if ((fp = fdopen(Fileno(fd), "w")) == NULL) { + rpmlog(RPMLOG_ERR, _("Unable to open stream: %s\n"), strerror(errno)); rc = RPMRC_FAIL; goto exit; } @@ -148,8 +143,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, fprintf(fp, "%s", sb); (void) fputs(buildPost, fp); - - (void) Fclose(xfd); + (void) fclose(fp); if (test) { rc = RPMRC_OK; @@ -194,6 +188,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, rc = RPMRC_OK; exit: + Fclose(fd); if (scriptName) { if (rc == RPMRC_OK) (void) unlink(scriptName); -- 2.7.4