From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T9HiZ-0007ku-C4 for qemu-devel@nongnu.org; Wed, 05 Sep 2012 11:40:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T9HiT-0005cU-GV for qemu-devel@nongnu.org; Wed, 05 Sep 2012 11:40:39 -0400 Sender: Paolo Bonzini Message-ID: <50477269.8050807@redhat.com> Date: Wed, 05 Sep 2012 17:40:25 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1346851582-9296-1-git-send-email-riegamaths@gmail.com> In-Reply-To: <1346851582-9296-1-git-send-email-riegamaths@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH] block: Don't forget to delete temporary file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: riegamaths@gmail.com Cc: qemu-trivial , qemu-devel Il 05/09/2012 15:26, riegamaths@gmail.com ha scritto: > From: Dunrong Huang > > The caller would not delete temporary file after failed get_tmp_filename(). > > Signed-off-by: Dunrong Huang > --- > block.c | 6 +++++- > 1 个文件被修改,插入 5 行(+),删除 1 行(-) > > diff --git a/block.c b/block.c > index 074987e..2bc9f75 100644 > --- a/block.c > +++ b/block.c > @@ -433,7 +433,11 @@ int get_tmp_filename(char *filename, int size) > return -EOVERFLOW; > } > fd = mkstemp(filename); > - if (fd < 0 || close(fd)) { > + if (fd < 0) { > + return -errno; > + } > + if (close(fd) != 0) { > + unlink(filename); > return -errno; > } > return 0; > Not necessary, mkstemp will not create a file if it returns an error. Paolo