| www.delorie.com/archives/browse.cgi | search |
| X-Spam-Check-By: | sourceware.org |
| Message-ID: | <44187B91.3070801@usa.net> |
| Date: | Wed, 15 Mar 2006 14:39:45 -0600 |
| From: | Paul Mattes <paul DOT mattes AT usa DOT net> |
| User-Agent: | Mozilla Thunderbird 1.0.2 (Windows/20050317) |
| MIME-Version: | 1.0 |
| To: | cygwin AT cygwin DOT com |
| Subject: | Memory leak in vsnprintf |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
I believe I have found a memory leak in the Cygwin version of
vsnprintf(). If it is called with a NULL 'str' parameter and a 0
'length', it leaks a BUFSIZ-sized buffer. (Per C99 and SUSv3, calling
vsnprintf() with a NULL 'str' and 0 'length' is a way to find out how
big the formatted string would be without actually storing it anywhere.)
I see that Cygwin's vsnprintf() comes from newlib. Should I report this
to them instead?
Here is an example program:
#include <stdio.h>
#include <stdarg.h>
int
waste_it(char *fmt, ...)
{
int ns;
va_list a;
va_start(a, fmt);
ns = vsnprintf(NULL, 0, fmt, a);
va_end(a);
return ns;
}
main(int argc, char *argv[])
{
int i;
int n;
for (i = 0; i < 10000; i++) {
n += waste_it("%s foo %d", "hello", 49);
}
}
This program will consume quite a lot of memory on Cygwin.
--
pdm
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |