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]