Index: trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp
===================================================================
--- trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp	(revision 36661)
+++ trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp	(revision 36662)
@@ -80,5 +80,5 @@
         return VERR_INTERNAL_ERROR;
     }
-    if (!mDisplay.init())
+    if (!(mDisplay = XOpenDisplay(NULL)))
     {
         LogRel(("VBoxClient: seamless guest object failed to acquire a connection to the display.\n"));
@@ -127,5 +127,5 @@
 {
     LogRelFlowFunc(("called\n"));
-    XSelectInput(mDisplay, DefaultRootWindow(mDisplay.get()), SubstructureNotifyMask);
+    XSelectInput(mDisplay, DefaultRootWindow(mDisplay), SubstructureNotifyMask);
 }
 
@@ -133,5 +133,5 @@
 {
     LogRelFlowFunc(("called\n"));
-    XSelectInput(mDisplay, DefaultRootWindow(mDisplay.get()), 0);
+    XSelectInput(mDisplay, DefaultRootWindow(mDisplay), 0);
 }
 
@@ -144,5 +144,5 @@
     LogRelFlowFunc(("called\n"));
     freeWindowTree();
-    addClients(DefaultRootWindow(mDisplay.get()));
+    addClients(DefaultRootWindow(mDisplay));
     mChanged = true;
 }
@@ -160,16 +160,17 @@
     Window hRealRoot, hParent;
     /** The list of children of the root supplied, raw pointer */
-    Window *phChildrenRaw;
+    Window *phChildrenRaw = NULL;
     /** The list of children of the root supplied, auto-pointer */
-    VBoxGuestX11Pointer<Window> phChildren;
+    Window *phChildren;
     /** The number of children of the root supplied */
     unsigned cChildren;
 
     LogRelFlowFunc(("\n"));
-    if (!XQueryTree(mDisplay.get(), hRoot, &hRealRoot, &hParent, &phChildrenRaw, &cChildren))
+    if (!XQueryTree(mDisplay, hRoot, &hRealRoot, &hParent, &phChildrenRaw, &cChildren))
         return;
     phChildren = phChildrenRaw;
     for (unsigned i = 0; i < cChildren; ++i)
-        addClientWindow(phChildren.get()[i]);
+        addClientWindow(phChildren[i]);
+    XFree(phChildrenRaw);
     LogRelFlowFunc(("returning\n"));
 }
@@ -204,5 +205,5 @@
     if (fAddWin)
     {
-        VBoxGuestX11Pointer<XRectangle> rects;
+        XRectangle *pRects;
         int cRects = 0, iOrdering;
         bool hasShape = false;
@@ -213,14 +214,14 @@
         {
             XShapeSelectInput(mDisplay, hWin, ShapeNotifyMask);
-            rects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects, &iOrdering);
-            if (0 == rects.get())
+            pRects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects, &iOrdering);
+            if (!pRects)
                 cRects = 0;
             else
             {
                 if (   (cRects > 1)
-                    || (rects.get()[0].x != 0)
-                    || (rects.get()[0].y != 0)
-                    || (rects.get()[0].width != winAttrib.width)
-                    || (rects.get()[0].height != winAttrib.height)
+                    || (pRects[0].x != 0)
+                    || (pRects[0].y != 0)
+                    || (pRects[0].width != winAttrib.width)
+                    || (pRects[0].height != winAttrib.height)
                    )
                     hasShape = true;
@@ -228,5 +229,6 @@
         }
         mGuestWindows.addWindow(hWin, hasShape, winAttrib.x, winAttrib.y,
-                                winAttrib.width, winAttrib.height, cRects, rects);
+                                winAttrib.width, winAttrib.height, cRects,
+                                pRects);
     }
     LogRelFlowFunc(("returning\n"));
@@ -241,6 +243,6 @@
 bool VBoxGuestSeamlessX11::isVirtualRoot(Window hWin)
 {
-    unsigned char *windowTypeRaw;
-    VBoxGuestX11Pointer<Atom> windowType;
+    unsigned char *windowTypeRaw = NULL;
+    Atom *windowType;
     unsigned long ulCount;
     bool rc = false;
@@ -250,9 +252,11 @@
     if (windowTypeRaw != NULL)
     {
-        windowType = reinterpret_cast<Atom *>(windowTypeRaw);
+        windowType = (Atom *)(windowTypeRaw);
         if (   (ulCount != 0)
             && (*windowType == XInternAtom(mDisplay, WM_TYPE_DESKTOP_PROP, True)))
             rc = true;
     }
+    if (windowTypeRaw)
+        XFree(windowTypeRaw);
     LogRelFlowFunc(("returning %s\n", rc ? "true" : "false"));
     return rc;
@@ -336,13 +340,15 @@
         if (iter->second->mhasShape)
         {
-            VBoxGuestX11Pointer<XRectangle> rects;
+            XRectangle *pRects;
             int cRects = 0, iOrdering;
 
-            rects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding,
-                                        &cRects, &iOrdering);
-            if (rects.get() == NULL)
+            pRects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding,
+                                         &cRects, &iOrdering);
+            if (!pRects)
                 cRects = 0;
+            if (iter->second->mpRects)
+                XFree(iter->second->mpRects);
             iter->second->mcRects = cRects;
-            iter->second->mapRects = rects;
+            iter->second->mpRects = pRects;
         }
         mChanged = true;
@@ -384,14 +390,16 @@
     if (iter != mGuestWindows.end())
     {
-        VBoxGuestX11Pointer<XRectangle> rects;
+        XRectangle *pRects;
         int cRects = 0, iOrdering;
 
-        rects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects,
-                                    &iOrdering);
-        if (rects.get() == NULL)
+        pRects = XShapeGetRectangles(mDisplay, hWin, ShapeBounding, &cRects,
+                                     &iOrdering);
+        if (!pRects)
             cRects = 0;
         iter->second->mhasShape = true;
+        if (iter->second->mpRects)
+            XFree(iter->second->mpRects);
         iter->second->mcRects = cRects;
-        iter->second->mapRects = rects;
+        iter->second->mpRects = pRects;
         mChanged = true;
     }
@@ -440,13 +448,13 @@
                 RTRECT rect;
                 rect.xLeft   =   it->second->mX
-                                + it->second->mapRects.get()[i].x;
+                                + it->second->mpRects[i].x;
                 rect.yBottom =   it->second->mY
-                                + it->second->mapRects.get()[i].y
-                                + it->second->mapRects.get()[i].height;
+                                + it->second->mpRects[i].y
+                                + it->second->mpRects[i].height;
                 rect.xRight  =   it->second->mX
-                                + it->second->mapRects.get()[i].x
-                                + it->second->mapRects.get()[i].width;
+                                + it->second->mpRects[i].x
+                                + it->second->mpRects[i].width;
                 rect.yTop    =   it->second->mY
-                                + it->second->mapRects.get()[i].y;
+                                + it->second->mpRects[i].y;
                 apRects.get()->push_back(rect);
             }
@@ -484,5 +492,5 @@
     XClientMessageEvent clientMessage = { ClientMessage, 0, 0, 0, 0, 0, 8 };
 
-    if (0 != XSendEvent(mDisplay, DefaultRootWindow(mDisplay.get()), false, PropertyChangeMask,
+    if (0 != XSendEvent(mDisplay, DefaultRootWindow(mDisplay), false, PropertyChangeMask,
                    reinterpret_cast<XEvent *>(&clientMessage)))
     {
Index: trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h
===================================================================
--- trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h	(revision 36661)
+++ trunk/src/VBox/Additions/x11/VBoxClient/seamless-x11.h	(revision 36662)
@@ -36,132 +36,4 @@
 /* This is defined wrong in my X11 header files! */
 #define VBoxShapeNotify 64
-
-/**
- * Wrapper class around the VBoxGuestX11Pointer to provide reference semantics.
- * See auto_ptr in the C++ <memory> header.
- */
-template <class T>
-struct VBoxGuestX11PointerRef
-{
-    T *mValue;
-
-    VBoxGuestX11PointerRef(T* pValue) { mValue = pValue; }
-};
-
-/** An auto pointer for pointers which have to be XFree'd. */
-template <class T>
-class VBoxGuestX11Pointer
-{
-private:
-    T *mValue;
-public:
-    VBoxGuestX11Pointer(T *pValue = 0) { mValue = pValue; }
-    ~VBoxGuestX11Pointer() { if (0 != mValue) XFree(mValue); }
-
-    /** release method to get the pointer's value and "reset" the pointer. */
-    T *release(void) { T *pTmp = mValue; mValue = 0; return pTmp; }
-
-    /** reset the pointer value to zero or to another pointer. */
-    void reset(T* pValue = 0) { if (pValue != mValue) { XFree(mValue); mValue = pValue; } }
-
-    /** Copy constructor */
-    VBoxGuestX11Pointer(VBoxGuestX11Pointer &orig) { mValue = orig.release(); }
-
-    /** Copy from equivalent class */
-    template <class T1>
-    VBoxGuestX11Pointer(VBoxGuestX11Pointer<T1> &orig) { mValue = orig.release(); }
-
-    /** Assignment operator. */
-    VBoxGuestX11Pointer& operator=(VBoxGuestX11Pointer &orig)
-    {
-        reset(orig.release());
-        return *this;
-    }
-
-    /** Assignment from equivalent class. */
-    template <class T1>
-    VBoxGuestX11Pointer& operator=(VBoxGuestX11Pointer<T1> &orig)
-    {
-        reset(orig.release);
-        return *this;
-    }
-
-    /** Assignment from a pointer. */
-    VBoxGuestX11Pointer& operator=(T *pValue)
-    {
-        if (0 != mValue)
-        {
-            XFree(mValue);
-        }
-        mValue = pValue;
-        return *this;
-    }
-
-    /** Dereference with * operator. */
-    T &operator*() { return *mValue; }
-
-    /** Dereference with -> operator. */
-    T *operator->() { return mValue; }
-
-    /** Accessing the value inside. */
-    T *get(void) { return mValue; }
-
-    /** Convert a reference structure into an X11 pointer. */
-    VBoxGuestX11Pointer(VBoxGuestX11PointerRef<T> ref) { mValue = ref.mValue; }
-
-    /** Assign from a reference structure into an X11 pointer. */
-    VBoxGuestX11Pointer& operator=(VBoxGuestX11PointerRef<T> ref)
-    {
-        if (ref.mValue != mValue)
-        {
-            XFree(mValue);
-            mValue = ref.mValue;
-        }
-        return *this;
-    }
-
-    /** Typecast an X11 pointer to a reference structure. */
-    template <class T1>
-    operator VBoxGuestX11PointerRef<T1>() { return VBoxGuestX11PointerRef<T1>(release()); }
-
-    /** Typecast an X11 pointer to an X11 pointer around a different type. */
-    template <class T1>
-    operator VBoxGuestX11Pointer<T1>() { return VBoxGuestX11Pointer<T1>(release()); }
-};
-
-/**
- * Wrapper class around an X11 display pointer which takes care of closing the display
- * when it is destroyed at the latest.
- */
-class VBoxGuestX11Display
-{
-private:
-    Display *mDisplay;
-public:
-    VBoxGuestX11Display(void) { mDisplay = NULL; }
-    bool init(char *name = NULL)
-    {
-        LogRelFlowFunc(("\n"));
-        mDisplay = XOpenDisplay(name);
-        LogRelFlowFunc(("returning\n"));
-        return (mDisplay != NULL);
-    }
-    operator Display *() { return mDisplay; }
-    Display *get(void) { return mDisplay; }
-    bool isValid(void) { return (mDisplay != NULL); }
-    int close(void)
-    {
-        LogRelFlowFunc(("\n"));
-        int rc = XCloseDisplay(mDisplay);
-        mDisplay = NULL;
-        LogRelFlowFunc(("returning\n"));
-        return rc;
-    }
-    ~VBoxGuestX11Display()
-    {
-        if (mDisplay != NULL)
-            close();
-    }
-};
 
 /** Structure containing information about a guest window's position and visible area.
@@ -177,13 +49,19 @@
     /** Number of rectangles used to represent the visible area. */
     int mcRects;
-    /** Rectangles representing the visible area.  These must be allocated by XMalloc
-        and will be freed automatically if non-null when the class is destroyed. */
-    VBoxGuestX11Pointer<XRectangle> mapRects;
+    /** Rectangles representing the visible area.  These must be allocated
+     * by XMalloc and will be freed automatically if non-null when the class
+     * is destroyed. */
+    XRectangle *mpRects;
     /** Constructor. */
     VBoxGuestWinInfo(bool hasShape, int x, int y, int w, int h, int cRects,
-                     VBoxGuestX11Pointer<XRectangle> rects)
-            : mapRects(rects)
-    {
-        mhasShape = hasShape, mX = x; mY = y; mWidth = w; mHeight = h; mcRects = cRects;
+                     XRectangle *pRects)
+            : mhasShape(hasShape), mX(x), mY(y), mWidth(w), mHeight(h),
+              mcRects(cRects), mpRects(pRects) {}
+
+    /** Destructor */
+    ~VBoxGuestWinInfo()
+    {
+        if (mpRects)
+            XFree(mpRects);
     }
 
@@ -238,9 +116,9 @@
 
     void addWindow(Window hWin, bool isMapped, int x, int y, int w, int h, int cRects,
-                   VBoxGuestX11Pointer<XRectangle> rects)
+                   XRectangle *pRects)
     {
         LogRelFlowFunc(("\n"));
         VBoxGuestWinInfo *pInfo = new VBoxGuestWinInfo(isMapped, x, y, w, h, cRects,
-                                                       rects);
+                                                       pRects);
         mWindows.insert(std::pair<Window, VBoxGuestWinInfo *>(hWin, pInfo));
         LogRelFlowFunc(("returning\n"));
@@ -274,5 +152,5 @@
     VBoxGuestSeamlessObserver *mObserver;
     /** Our connection to the X11 display we are running on. */
-    VBoxGuestX11Display mDisplay;
+    Display *mDisplay;
     /** Class to keep track of visible guest windows. */
     VBoxGuestWindowList mGuestWindows;
@@ -353,7 +231,6 @@
 
     VBoxGuestSeamlessX11(void)
-    {
-        mObserver = 0; mcRects = 0; mEnabled = false; mSupportsShape = false;
-    }
+        : mObserver(0), mDisplay(NULL), mcRects(0), mSupportsShape(false),
+          mEnabled(false) {}
 
     ~VBoxGuestSeamlessX11()
@@ -364,4 +241,6 @@
         }
         catch(...) {}
+        if (mDisplay)
+            XCloseDisplay(mDisplay);
     }
 };
