lundi 30 mars 2015

Getline in loop consuming constantly more memory in embedded linux



After running application over weekend I noticed in the morning that it was killed because no memory was left.


After commenting some parts of code, I see that this procedure might be a problem, but I can't figure out why.



void readData (char * path) {

// Reading and parsing config from file
FILE * fp;
size_t len = 0;
size_t read;

char *begin, *end, line[100], data[100];

fp = fopen(path, "r");
if (fp != NULL)
{
while ((read = getline(&line, &len, fp)) != -1) {
/* begin = strstr(line, "\"data\":[")+8;
end = strstr(begin, "]");
strncpy(data, begin,strlen(begin) - strlen(end));
data[strlen(begin) - strlen(end)] = 0;
*/
int tmp;

// sscanf(data,"%d,%d,%d,%d,%d,%d",&tmp,&ss.tensionRaw,&tmp,&tmp,&ss.depthRaw,&ss.speedRaw);
ss.tension = cs.tensionCoeff * ss.tensionRaw;
ss.speed = cs.speedCoeff * ss.speedRaw;
ss.depth = cs.depthCoeff * ss.depthRaw;

/* begin = strstr(line, "\"failedRequests\":\"")+18;
end = strstr(begin, "\"");
strncpy(data, begin,strlen(begin) - strlen(end));
data[strlen(begin) - strlen(end)] = 0;
ss.connectionOK = atoi(data);*/
}
}
fclose(fp);
}


Can getline cause problems like this? I monitor memory use of app by "top" and every 15-20 sec it gets around 4K more. When i comment whole while loop, it's not increasing.




Aucun commentaire:

Enregistrer un commentaire