From: Simon Wilkinson Date: Sun, 13 Jun 2010 00:44:27 +0000 (+0100) Subject: bucoord: Use mkstemp properly X-Git-Tag: openafs-devel-1_5_75~149 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=0efea8e2b1162ef88ef27daeffa1acb69c850566 bucoord: Use mkstemp properly Use mkstemp wherever we have it available, to silence warnings about mktemp's safety. When we do use mkstemp, use it properly. It doesn't return void, it returns an open filehandle. Convert this filehandle into a FILE *, rather than throwing it away, and leaking an open file descriptor. Caught by clang-analyzer Change-Id: Ib5864f684c6d5a8686e0a872364a645c90a29390 Reviewed-on: http://gerrit.openafs.org/2144 Reviewed-by: Russ Allbery Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/bucoord/ubik_db_if.c b/src/bucoord/ubik_db_if.c index dbf253b..c0de8ef 100644 --- a/src/bucoord/ubik_db_if.c +++ b/src/bucoord/ubik_db_if.c @@ -1217,17 +1217,25 @@ int bc_openTextFile(udbClientTextP ctPtr, char *tmpFileName) { int code = 0; +#ifdef HAVE_MKSTEMP + int fd; +#endif - if (ctPtr->textStream != NULL) + if (ctPtr->textStream != NULL) { fclose(ctPtr->textStream); + ctPtr->textStream = NULL; + } sprintf(tmpFileName, "%s/bu_XXXXXX", gettmpdir()); -#ifdef AFS_LINUX20_ENV - mkstemp(tmpFileName); +#ifdef HAVE_MKSTEMP + fd = mkstemp(tmpFileName); + if (fd == -1) + ERROR(BUDB_INTERNALERROR); + ctPtr->textStream = fdopen(fd, "w+"); #else mktemp(tmpFileName); -#endif ctPtr->textStream = fopen(tmpFileName, "w+"); +#endif if (ctPtr->textStream == NULL) ERROR(BUDB_INTERNALERROR);