Go Back   nV News Forums > Linux Support Forums > NVIDIA Linux

Newegg Daily Deals

Thread Tools
Old 04-10-05, 02:10 PM   #1
Registered User
Join Date: Sep 2002
Posts: 2,262
Default Double-XCloseDisplay() (?) in nvidia-settings

So I tried running nvidia-settings after moving to a new system (I upgraded the whole thing from LFS 5+NPTL to LFS 6.1, which meant moving from XFree86 to X.org 6.8.0), and it segfaulted.

I thought it may have been related to the config file (possibly), so I renamed it and reran the program, and it came up OK. But it segfaulted when exiting, and every time after that it also segfaulted. It did seem to load the settings OK, though.

After a bunch of debugging, it seems that the problem is with nv_alloc_ctrl_handles and the call to NvCtrlAttributeInit, in conjunction with nv_free_ctrl_handles and the call to NvCtrlAttributeClose.

When nv_alloc_ctrl_handles is called, it does an XOpenDisplay on h->display (which is the value of the DISPLAY environment variable in my case), and stores the resulting Display pointer into h->dpy. When it calls NvCtrlAttributeInit (which is in NvCtrlAttributes.c), it passes the resulting h->dpy value in, and NvCtrlAttributeInit copies it into the NvCtrlAttributePrivateHandle that it creates. (From the perspective of nv_alloc_ctrl_handles, the display pointer is copied from h->dpy to h->h[i]->dpy.) Then it calls NvCtrlGlxAttributesInit, which re-opens the same display. (It calls XDisplayString on the ->dpy value, and calls XOpenDisplay on that.)

Later, when nv_free_ctrl_handles is called, it calls NvCtrlAttributeClose, which calls NvCtrlGlxAttributesClose, which does an XCloseDisplay on its Display pointer. When all the NvCtrlAttributeClose calls are done, nv_free_ctrl_handles calls XCloseDisplay again, which segfaults on my machine. This may be because the ->dpy values are the same, or I suppose it could be a bug in my Xlib library (so they don't handle >1 display properly).

I'm not sure how to fix it correctly, but this patch at least fixes the segfault for me. It wouldn't surprise me if both handles need to be closed, though...

diff -Naur nvidia-settings-1.0/src/query-assign.c nvidia-settings-1.0-patched/src/query-assign.c
--- nvidia-settings-1.0/src/query-assign.c	2005-03-22 10:36:32.000000000 -0500
+++ nvidia-settings-1.0-patched/src/query-assign.c	2005-04-10 12:56:44.000000000 -0400
@@ -141,6 +141,7 @@
     else h->display = NULL;
     h->dpy = XOpenDisplay(h->display);
+    h->dpy_was_copied = 0;
     if (h->dpy) {
@@ -152,6 +153,7 @@
         for (i = 0; i < h->num_screens; i++) {
             h->h[i] = NvCtrlAttributeInit
                 (h->dpy, i, NV_CTRL_ATTRIBUTES_ALL_SUBSYSTEMS);
+            h->dpy_was_copied = 1;
             h->screen_names[i] = NvCtrlGetDisplayName(h->h[i]);
@@ -196,7 +198,8 @@
         if (h->h) free(h->h);
         if (h->screen_names) free(h->screen_names);
-        XCloseDisplay(h->dpy);
+        if(!h->dpy_was_copied)
+            XCloseDisplay(h->dpy);
diff -Naur nvidia-settings-1.0/src/query-assign.h nvidia-settings-1.0-patched/src/query-assign.h
--- nvidia-settings-1.0/src/query-assign.h	2005-03-22 10:36:32.000000000 -0500
+++ nvidia-settings-1.0-patched/src/query-assign.h	2005-04-10 12:55:12.000000000 -0400
@@ -46,6 +46,7 @@
 typedef struct {
     char *display;
     Display *dpy;
+    int dpy_was_copied;
     int num_screens;
     NvCtrlAttributeHandle **h;
     uint32 *d;
Registered Linux User #219692
bwkaz is offline   Reply With Quote
Old 04-11-05, 12:06 AM   #2
NVIDIA Corporation
zander's Avatar
Join Date: Aug 2002
Posts: 3,740
Default Re: Double-XCloseDisplay() (?) in nvidia-settings

@bwkaz: thanks for your report; does the attached patch resolve the crash problem you're seeing?
Attached Files
File Type: txt nvidia-settings-1.0-1253282.diff.txt (1.0 KB, 175 views)
zander is offline   Reply With Quote
Old 04-15-05, 09:32 PM   #3
Registered User
Join Date: Sep 2002
Posts: 2,262
Default Re: Double-XCloseDisplay() (?) in nvidia-settings

Sorry about the delay, I sort of forgot all about this.

Anyway, no, that patch does not seem to fix the segfault. I am really no longer sure that the problem is in nvidia-settings, either, though. This is a gdb session of me running the patched version of the program:

$ gdb ./nvidia-settings 
GNU gdb 6.3
This GDB was configured as "i686-pc-linux-gnu"...
  Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) break nv_free_ctrl_handles 
Breakpoint 1 at 0x80509f8: file src/query-assign.c, line 181.
(gdb) run
Starting program: /home/bilbo/nvidia-settings-1.0/nvidia-settings 

Breakpoint 1, nv_free_ctrl_handles (h=0x1) at src/query-assign.c:181
181     {
(gdb) next
184         if (!h) return;
186         if (h->display) free(h->display);
(gdb) print h->display
$1 = 0x819eda8 ":0.0"
(gdb) next
188         if (h->dpy) {
198             XCloseDisplay(h->dpy);
201             for (i = 0; i < h->num_screens; i++) {
198             XCloseDisplay(h->dpy);
WTF is going on here -- why is the XCloseDisplay line being executed twice? I'm wondering if maybe this is a bug in my compiler, or in gdb.

Well, the first few times I was running it, it was compiled with "-O2 -march=athlon-xp" (I didn't read the Makefile closely enough). I recompiled with "-O0" inserted after those, and gdb only showed the XCloseDisplay line once (but that first execution still segfaulted).

Any ideas? Could this be a bug in my Xlib? Or might there be some kind of malloc arena corruption happening somewhere else that's showing itself as a segfault in free()? (Actually, I'm not positive that it's segfaulting in free() -- all I know is that it's somewhere deep down in the bowels of XCloseDisplay(). But I would assume that XCloseDisplay calls free at some point.) This is X.org version 6.8.2, compiled by me. (...so there's no saying for sure that it compiled correctly either.)

Thank you!
Registered Linux User #219692
bwkaz is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Thoughts from console owners on NVIDIA's GEFORCE GRID MikeC Console World 11 05-27-12 08:43 AM
Need Help Installing NVIDIA Tesla M2070Q in Linux RHEL5 Ferianto85 NVIDIA Linux 0 05-18-12 08:35 PM
Found Simpsons in NVIDIA registry settings! ShVen NVIDIA GeForce 7, 8, And 9 Series 6 10-06-02 09:26 PM

All times are GMT -5. The time now is 10:00 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.