aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2011-10-10 17:58:31 +0200
committerReinhard Tartler <siretart@tauware.de>2011-10-10 17:58:31 +0200
commit1c25e92b9ea5811d8ab9c2bfdc0dcb2e4d21bd0a (patch)
tree56b1d4196538a8abb7747e8455b59aa778d6b948 /nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original
parent266b5554943baffafbf1d574f567283cc9792278 (diff)
downloadnx-libs-1c25e92b9ea5811d8ab9c2bfdc0dcb2e4d21bd0a.tar.gz
nx-libs-1c25e92b9ea5811d8ab9c2bfdc0dcb2e4d21bd0a.tar.bz2
nx-libs-1c25e92b9ea5811d8ab9c2bfdc0dcb2e4d21bd0a.zip
Imported nxagent-3.2.0-10.tar.gznxagent/3.2.0-10
Summary: Imported nxagent-3.2.0-10.tar.gz Keywords: Imported nxagent-3.2.0-10.tar.gz into Git repository
Diffstat (limited to 'nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original77
1 files changed, 77 insertions, 0 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original b/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original
index 9af5c4187..91e03cb0e 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original
+++ b/nx-X11/programs/Xserver/hw/nxagent/X/NXresource.c.NX.original
@@ -201,6 +201,10 @@ void RegisterResourceName (RESTYPE type, char *name)
#endif
+#ifdef NXAGENT_SERVER
+static int nxagentResChangedFlag = 0;
+#endif
+
RESTYPE
CreateNewResourceType(DeleteType deleteFunc)
{
@@ -590,6 +594,9 @@ AddResource(XID id, RESTYPE type, pointer value)
res->value = value;
*head = res;
rrec->elements++;
+ #ifdef NXAGENT_SERVER
+ nxagentResChangedFlag = 1;
+ #endif
if (!(id & SERVER_BIT) && (id >= rrec->expectID))
rrec->expectID = id + 1;
return TRUE;
@@ -675,6 +682,9 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
RESTYPE rtype = res->type;
*prev = res->next;
elements = --*eltptr;
+ #ifdef NXAGENT_SERVER
+ nxagentResChangedFlag = 1;
+ #endif
if (rtype & RC_CACHED)
FlushClientCaches(res->id);
if (rtype != skipDeleteFuncType)
@@ -715,6 +725,9 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
if (res->id == id && res->type == type)
{
*prev = res->next;
+ #ifdef NXAGENT_SERVER
+ nxagentResChangedFlag = 1;
+ #endif
if (type & RC_CACHED)
FlushClientCaches(res->id);
if (!skipFree)
@@ -809,12 +822,44 @@ RestartLoop:
next = this->next;
if (!type || this->type == type) {
elements = *eltptr;
+
+ /*
+ * FIXME:
+ * It is not safe to let a function change the resource
+ * table we are reading!
+ */
+
+ #ifdef NXAGENT_SERVER
+ nxagentResChangedFlag = 0;
+ #endif
(*func)(this->value, this->id, cdata);
+
+ /*
+ * Avoid that a call to RebuildTable() could invalidate the
+ * pointer. This is safe enough, because in RebuildTable()
+ * the new pointer is allocated just before the old one is
+ * freed, so it can't point to the same address.
+ */
+
#ifdef NXAGENT_SERVER
if (*resptr != resources)
goto RestartLoop;
#endif
+
+ /*
+ * It's not enough to check if the number of elements has
+ * changed, beacause it could happen that the number of
+ * resources that have been added matches the number of
+ * the freed ones.
+ * 'nxagentResChangedFlag' is set if a resource has been
+ * added or freed.
+ */
+
+ #ifdef NXAGENT_SERVER
+ if (*eltptr != elements || nxagentResChangedFlag)
+ #else
if (*eltptr != elements)
+ #endif
next = resources[i]; /* start over */
}
}
@@ -861,12 +906,44 @@ RestartLoop:
{
next = this->next;
elements = *eltptr;
+
+ /*
+ * FIXME:
+ * It is not safe to let a function change the resource
+ * table we are reading!
+ */
+
+ #ifdef NXAGENT_SERVER
+ nxagentResChangedFlag = 0;
+ #endif
(*func)(this->value, this->id, this->type, cdata);
+
+ /*
+ * Avoid that a call to RebuildTable() could invalidate the
+ * pointer. This is safe enough, because in RebuildTable()
+ * the new pointer is allocated just before the old one is
+ * freed, so it can't point to the same address.
+ */
+
#ifdef NXAGENT_SERVER
if (*resptr != resources)
goto RestartLoop;
#endif
+
+ /*
+ * It's not enough to check if the number of elements has
+ * changed, beacause it could happen that the number of
+ * resources that have been added matches the number of
+ * the freed ones.
+ * 'nxagentResChangedFlag' is set if a resource has been
+ * added or freed.
+ */
+
+ #ifdef NXAGENT_SERVER
+ if (*eltptr != elements || nxagentResChangedFlag)
+ #else
if (*eltptr != elements)
+ #endif
next = resources[i]; /* start over */
}
}