Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting to syslog causes heap allocation to steadily increase in size
    text
    copied!<p>Yesterday I was wondering why the number of allocs and frees on the heap kept creeping up: <a href="https://stackoverflow.com/questions/11730265/valgrind-understanding-bytes-allocated-increase-in-heap-summary">Valgrind understanding bytes allocated increase in heap summary?</a></p> <p>Today I have found the culprit, however I do not understand why:</p> <pre><code>openlog ("XYSV", LOG_PID, LOG_SYSLOG); syslog (LOG_NOTICE, "server started by %s(%d) on port %d", getenv("USER"),getuid (),servPort); closelog(); for (;;) /* Run forever */ { clntSock = AcceptTCPConnection(servSock); char ipstr[INET6_ADDRSTRLEN]; /* Fork child process and report any errors */ if ((processID = fork()) &lt; 0) DieWithError("fork() failed"); else if (processID == 0) /* If this is the child process */ { close(servSock); /* Child closes parent socket */ HandleTCPClient(clntSock); exit(0); /* Child process terminates */ } openlog ("XYSV", LOG_PID, LOG_SYSLOG); //syslog(LOG_INFO,"%d : created new child process for connect from %s\n", (int) processID,ipstr); //syslog(LOG_INFO, "test"); closelog(); close(clntSock); /* Parent closes child socket descriptor */ childProcCount++; /* Increment number of outstanding child processes */ } </code></pre> <p>As soon as I uncomment the two syslog entries the allocs on the heap (reported by Valgrind) keep increasing. The allocs are also freed, however the total number of allocs keeps increasing and thus the size of the allocated memory. IMHO this would sooner or later cause the server to run out of mem.</p> <p>My question is: why would this write to the syslog cause the allocs to increase. I am closing the syslog nicely. The first syslog does not have an effect on the heap allocation. When I leave the open and close in place for the second write to the syslog and leave the actual write commented out everything is allright. As soon as I uncomment one or two of the syslog lines the allocs start creeping up.</p> <p>I must be overseeing something obvious.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload