Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH 2/7] lockfile: introduce alloc_lock_file() to avoid valgrind noise

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:43

Jonathan Nieder [off-list ref] writes:
Junio C Hamano wrote:
quoted
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.
quoted
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;
	}
Heh, shouldn't the last one assign from p->next?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help