Commit bed0d6ce authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Atoms.c: always duplicate strings before storing them in privAtomMap

Otherwise we will never be able to free the list because we do not know if free() is allowed or not.
parent 8a5c1d3d
...@@ -374,7 +374,7 @@ static unsigned int privAtomMapSize = 0; ...@@ -374,7 +374,7 @@ static unsigned int privAtomMapSize = 0;
static unsigned int privLastAtom = 0; static unsigned int privLastAtom = 0;
static void nxagentExpandCache(void); static void nxagentExpandCache(void);
static void nxagentWriteAtom(Atom, XlibAtom, const char*, Bool); static void nxagentWriteAtom(Atom, XlibAtom, const char*);
static AtomMap* nxagentFindAtomByRemoteValue(XlibAtom); static AtomMap* nxagentFindAtomByRemoteValue(XlibAtom);
static AtomMap* nxagentFindAtomByLocalValue(Atom); static AtomMap* nxagentFindAtomByLocalValue(Atom);
static AtomMap* nxagentFindAtomByName(char*, unsigned); static AtomMap* nxagentFindAtomByName(char*, unsigned);
...@@ -396,19 +396,9 @@ static void nxagentExpandCache(void) ...@@ -396,19 +396,9 @@ static void nxagentExpandCache(void)
* consequent allocation, then cache the atom-couple. * consequent allocation, then cache the atom-couple.
*/ */
static void nxagentWriteAtom(Atom local, XlibAtom remote, const char *string, Bool duplicate) static void nxagentWriteAtom(Atom local, XlibAtom remote, const char *string)
{ {
const char *s; const char *s = strdup(string);
/*
* We could remove this string duplication if we knew for sure that
* the server will not reset, since only at reset the dix layer
* frees all the atom names.
*/
if (duplicate)
{
s = strdup(string);
#ifdef WARNING #ifdef WARNING
if (s == NULL) if (s == NULL)
...@@ -416,11 +406,6 @@ static void nxagentWriteAtom(Atom local, XlibAtom remote, const char *string, Bo ...@@ -416,11 +406,6 @@ static void nxagentWriteAtom(Atom local, XlibAtom remote, const char *string, Bo
fprintf(stderr, "nxagentWriteAtom: Malloc failed.\n"); fprintf(stderr, "nxagentWriteAtom: Malloc failed.\n");
} }
#endif #endif
}
else
{
s = string;
}
if (privLastAtom == privAtomMapSize) if (privLastAtom == privAtomMapSize)
{ {
...@@ -515,7 +500,7 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet) ...@@ -515,7 +500,7 @@ static int nxagentInitAtomMap(char **atomNameList, int count, Atom *atomsRet)
if (ValidAtom(local)) if (ValidAtom(local))
{ {
nxagentWriteAtom(local, atom_list[i], name_list[i], False); nxagentWriteAtom(local, atom_list[i], name_list[i]);
} }
else else
{ {
...@@ -673,7 +658,7 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit) ...@@ -673,7 +658,7 @@ XlibAtom nxagentMakeAtom(char *string, unsigned int length, Bool Makeit)
} }
else else
{ {
nxagentWriteAtom(local, remote, string, True); nxagentWriteAtom(local, remote, string);
return remote; return remote;
} }
...@@ -732,7 +717,7 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local) ...@@ -732,7 +717,7 @@ XlibAtom nxagentLocalToRemoteAtom(Atom local)
return None; return None;
} }
nxagentWriteAtom(local, remote, string, True); nxagentWriteAtom(local, remote, string);
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: local [%d (%s)] -> remote [%d]\n", __func__, local, string, remote); fprintf(stderr, "%s: local [%d (%s)] -> remote [%d]\n", __func__, local, string, remote);
...@@ -809,7 +794,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote) ...@@ -809,7 +794,7 @@ Atom nxagentRemoteToLocalAtom(XlibAtom remote)
local = None; local = None;
} }
nxagentWriteAtom(local, remote, string, True); nxagentWriteAtom(local, remote, string);
#ifdef TEST #ifdef TEST
fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local); fprintf(stderr, "%s: remote [%d (%s)] -> local [%d]\n", __func__, remote, string, local);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment