Commit 58b3c8cd authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

Font.c: fix realloc bugs

parent acd45283
...@@ -192,7 +192,6 @@ void nxagentFreeFontCache(void) ...@@ -192,7 +192,6 @@ void nxagentFreeFontCache(void)
} }
SAFE_free(CACHE_ENTRY_PTR); SAFE_free(CACHE_ENTRY_PTR);
CACHE_ENTRY_PTR = NULL;
CACHE_INDEX = 0; CACHE_INDEX = 0;
CACHE_SIZE = 0; CACHE_SIZE = 0;
...@@ -289,16 +288,16 @@ void nxagentListRemoteAddName(const char *name, int status) ...@@ -289,16 +288,16 @@ void nxagentListRemoteAddName(const char *name, int status)
if (nxagentRemoteFontList.length == nxagentRemoteFontList.listSize) if (nxagentRemoteFontList.length == nxagentRemoteFontList.listSize)
{ {
/* FIXME: if realloc fails the pointer is lost! */ int num = nxagentRemoteFontList.listSize + 1000;
nxagentRemoteFontList.list = realloc(nxagentRemoteFontList.list, sizeof(nxagentFontRecPtr) nxagentFontRecPtr *tmp1 = realloc(nxagentRemoteFontList.list, sizeof(nxagentFontRecPtr) * num);
* (nxagentRemoteFontList.listSize + 1000));
if (nxagentRemoteFontList.list == NULL) if (tmp1 == NULL)
{ {
FatalError("Font: remote list memory re-allocation failed!.\n"); FatalError("Font: remote list memory re-allocation failed!.\n");
} }
nxagentRemoteFontList.listSize += 1000; nxagentRemoteFontList.list = tmp1;
nxagentRemoteFontList.listSize = num;
} }
if (pos < nxagentRemoteFontList.length) if (pos < nxagentRemoteFontList.length)
...@@ -542,15 +541,18 @@ Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont) ...@@ -542,15 +541,18 @@ Bool nxagentRealizeFont(ScreenPtr pScreen, FontPtr pFont)
if (CACHE_INDEX == CACHE_SIZE) if (CACHE_INDEX == CACHE_SIZE)
{ {
/* FIXME: if realloc fails the pointer is lost */ int num = CACHE_SIZE + 100;
CACHE_ENTRY_PTR = realloc(CACHE_ENTRY_PTR, sizeof(nxCacheFontEntryRecPtr) * (CACHE_SIZE + 100));
if (CACHE_ENTRY_PTR == NULL) nxCacheFontEntryRecPtr *tmp1 = realloc(CACHE_ENTRY_PTR,
sizeof(nxCacheFontEntryRecPtr) * num);
if (tmp1 == NULL)
{ {
FatalError("Font: Cache list memory re-allocation failed.\n"); FatalError("Font: Cache list memory re-allocation failed.\n");
} }
CACHE_SIZE += 100; CACHE_ENTRY_PTR = tmp1;
CACHE_SIZE = num;
} }
CACHE_ENTRY(CACHE_INDEX) = malloc(sizeof(nxCacheFontEntryRec)); CACHE_ENTRY(CACHE_INDEX) = malloc(sizeof(nxCacheFontEntryRec));
...@@ -888,22 +890,23 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id) ...@@ -888,22 +890,23 @@ static void nxagentCollectFailedFont(FontPtr fpt, XID id)
} }
else if (nxagentFailedToReconnectFonts.index == nxagentFailedToReconnectFonts.size - 1) else if (nxagentFailedToReconnectFonts.index == nxagentFailedToReconnectFonts.size - 1)
{ {
nxagentFailedToReconnectFonts.size *= 2; int num = 2 * nxagentFailedToReconnectFonts.size;
/* FIXME: if realloc fails the pointer is lost */
nxagentFailedToReconnectFonts.font = realloc(nxagentFailedToReconnectFonts.font,
nxagentFailedToReconnectFonts.size *
sizeof(FontPtr));
nxagentFailedToReconnectFonts.id = realloc(nxagentFailedToReconnectFonts.id, FontPtr *tmp1 = realloc(nxagentFailedToReconnectFonts.font, num * sizeof(FontPtr));
nxagentFailedToReconnectFonts.size * XID *tmp2 = realloc(nxagentFailedToReconnectFonts.id, num * sizeof(XID));
sizeof(XID));
if (nxagentFailedToReconnectFonts.font == NULL || nxagentFailedToReconnectFonts.id == NULL) if (tmp1 == NULL || tmp2 == NULL)
{ {
SAFE_free(tmp1);
SAFE_free(tmp2);
FatalError("Font: font not reconnected memory re-allocation failed!.\n"); FatalError("Font: font not reconnected memory re-allocation failed!.\n");
} }
nxagentFailedToReconnectFonts.size = num;
nxagentFailedToReconnectFonts.font = tmp1;
nxagentFailedToReconnectFonts.id = tmp2;
#ifdef NXAGENT_RECONNECT_FONT_DEBUG #ifdef NXAGENT_RECONNECT_FONT_DEBUG
fprintf(stderr,"nxagentCollectFailedFont: reallocated memory.\n "); fprintf(stderr,"nxagentCollectFailedFont: reallocated memory.\n ");
#endif #endif
......
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