Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Help, what's this memory leak?

Help, what's this memory leak?
Thread Tools
Dedicated MacNNer
Join Date: Sep 2000
Location: Brisbane, Queensland, Australia
Status: Offline
Reply With Quote
Dec 16, 2001, 01:08 AM
 
Hi

I have an odd problem. Granted I'm not very good at C, I have come across this particular problem which only shows up on OSX.

When using sprintf, snprintf, fprintf etc etc I get a memory leak problem when I substitute more than 1 float into one of these functions. Run the following code and load top in another window, have a look at how its chewing up ram (osx only). Btw, snprintf does the same thing.

Any ideas?

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
double double1, double2, double3;
char *doubleString;

while (1) {
double1 = 1.812412481;
double2 = 1.912931241;
double3 = 1.182371238;

doubleString = (char *) malloc(50);

/* why does this leak if i put in more than 1 floats to sprintf or fprintf or snprintf etc? */
sprintf(doubleString, "%f, %f, %f\n", double1, double2, double3);

free(doubleString);

usleep(1000);

}

return 0;
}[/LIST]
     
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Dec 16, 2001, 05:12 AM
 
That code should not leak. I have submitted it as a bug report.

-Peter
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:06 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2