Re: [PATCH 2/7] lockfile: introduce alloc_lock_file() to avoid valgrind noise
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Oct 6, 2010, 20:21 UTC
- Message-ID
- <20101006202130.GB2118@burratino>
- In-Reply-To
- <7vocb7yte4.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 7 quoted lines
> Hmm, I am getting > > cc1: warnings being treated as errors > lockfile.c:189: error: 'optimize' attribute directive ignored > make: *** [lockfile.o] Error 1 > > from this patch with gcc (Debian 4.3.2-1.1) 4.3.2
Unfortunate. With gcc 4.5 it works, but that isn't too useful.
> Aren't "struct lock_file" instances supposed to be reachable from the > linked list, i.e. lock_file_list? Why does valgrind consider that > elements on that list are leaked in the first place?
At exit, we walk the lock file list and clear it in the process. Which suggests a cleaner workaround (thanks!):
static void remove_lock_file(void)
{
pid_t me = getpid();
+ struct lock_file *p = lock_file_list;- while (lock_file_list) {
- if (lock_file_list->owner == me &&
- lock_file_list->filename[0]) {
- if (lock_file_list->fd >= 0)
- close(lock_file_list->fd);
- unlink_or_warn(lock_file_list->filename);
- }
- lock_file_list = lock_file_list->next;
+ while (p) {
+ if (p->owner == me &&
+ p->filename[0]) {
+ if (p->fd >= 0)
+ close(p->fd);
+ unlink_or_warn(p->filename);
+ }
+ p = lock_file_list->next;
}