From 2c0087ea00a28c65a7b118aaa00e768dcf5886ad Mon Sep 17 00:00:00 2001
From: "Joel E. Denny" <jdenny@clemson.edu>
Date: Tue, 15 Dec 2009 10:07:39 +0100
Subject: [PATCH] *printf: Fix memory leak.

---
 ChangeLog      | 9 +++++++++
 lib/dprintf.c  | 3 +++
 lib/fprintf.c  | 5 ++++-
 lib/vdprintf.c | 3 +++
 lib/vfprintf.c | 5 ++++-
 5 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2756f670bb..0f42ccf506 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-12-15  Joel E. Denny  <jdenny@clemson.edu>
+            Bruno Haible  <bruno@clisp.org>
+
+	*printf: Fix memory leak.
+	* lib/fprintf.c (fprintf): Free memory allocated by vasnprintf.
+	* lib/vfprintf.c (vfprintf): Likewise.
+	* lib/dprintf.c (dprintf): Likewise.
+	* lib/vdprintf.c (vdprintf): Likewise.
+
 2009-12-14  Eric Blake  <ebb9@byu.net>
 
 	accept4: adjust module dependencies
diff --git a/lib/dprintf.c b/lib/dprintf.c
index 70f992f0e5..99ee6af7f3 100644
--- a/lib/dprintf.c
+++ b/lib/dprintf.c
@@ -57,6 +57,9 @@ dprintf (int fd, const char *format, ...)
       return -1;
     }
 
+  if (output != buf)
+    free (output);
+
   if (len > INT_MAX)
     {
       errno = EOVERFLOW;
diff --git a/lib/fprintf.c b/lib/fprintf.c
index eb1cf8e366..dc8fcfb0b0 100644
--- a/lib/fprintf.c
+++ b/lib/fprintf.c
@@ -1,5 +1,5 @@
 /* Formatted output to a stream.
-   Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -63,6 +63,9 @@ fprintf (FILE *fp, const char *format, ...)
       return -1;
     }
 
+  if (output != buf)
+    free (output);
+
   if (len > INT_MAX)
     {
       errno = EOVERFLOW;
diff --git a/lib/vdprintf.c b/lib/vdprintf.c
index 2b0da8a289..77c8c6ea03 100644
--- a/lib/vdprintf.c
+++ b/lib/vdprintf.c
@@ -54,6 +54,9 @@ vdprintf (int fd, const char *format, va_list args)
       return -1;
     }
 
+  if (output != buf)
+    free (output);
+
   if (len > INT_MAX)
     {
       errno = EOVERFLOW;
diff --git a/lib/vfprintf.c b/lib/vfprintf.c
index 6e3d595f81..4b599b124b 100644
--- a/lib/vfprintf.c
+++ b/lib/vfprintf.c
@@ -1,5 +1,5 @@
 /* Formatted output to a stream.
-   Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2006-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -60,6 +60,9 @@ vfprintf (FILE *fp, const char *format, va_list args)
       return -1;
     }
 
+  if (output != buf)
+    free (output);
+
   if (len > INT_MAX)
     {
       errno = EOVERFLOW;
-- 
2.30.2