Cleanup the saved_builtin_dir mess. Fixes that the xserver crashed when it was
[openwrt/svn-archive/archive.git] / Xorg / xorg / lib / libXfont / patches / 010-cleanup-saved-builtins.patch
1 diff --git a/src/builtins/dir.c b/src/builtins/dir.c
2 index 1f7f547..3a8d944 100644
3 --- a/src/builtins/dir.c
4 +++ b/src/builtins/dir.c
5 @@ -29,172 +29,32 @@
6 #endif
7 #include "builtin.h"
8
9 -static BuiltinDirPtr
10 -BuiltinDirsDup (const BuiltinDirPtr a_dirs,
11 - int a_dirs_len)
12 -{
13 - BuiltinDirPtr dirs=NULL ;
14 - int i=0 ;
15 -
16 - if (!a_dirs)
17 - return NULL ;
18 -
19 - dirs = xcalloc (a_dirs_len, sizeof (BuiltinDirRec)) ;
20 - if (!dirs)
21 - return NULL ;
22 -
23 - for (i=0; i < a_dirs_len; i++) {
24 - int len = strlen (a_dirs[i].file_name) ;
25 - dirs[i].file_name = xcalloc (1, len) ;
26 - memmove (dirs[i].file_name, a_dirs[i].file_name, len);
27 - len = strlen (a_dirs[i].font_name) ;
28 - dirs[i].font_name = xcalloc (1, len) ;
29 - memmove (dirs[i].font_name, a_dirs[i].font_name, len);
30 - }
31 - return dirs ;
32 -}
33 -
34 -/**
35 - * Copy a_save back into a_cur
36 - * @param a_cur the instance of BuiltinDir to restore
37 - * @param a_saved the saved instance of BuiltinDir to copy into a_cur
38 - * @return 0 if went okay, 1 otherwise.
39 - */
40 -static int
41 -BuiltinDirRestore (BuiltinDirPtr a_cur,
42 - const BuiltinDirPtr a_saved)
43 -{
44 - if (!a_cur)
45 - return 1 ;
46 - if (!a_saved)
47 - return 0 ;
48 -
49 - if (a_saved->font_name)
50 - memmove (a_cur->font_name, a_saved->font_name, strlen (a_saved->font_name)) ;
51 - return 0 ;
52 -}
53 -
54 -
55 -static int
56 -BuiltinDirsRestore (BuiltinDirPtr a_cur_tab,
57 - const BuiltinDirPtr a_saved_tab,
58 - int a_tab_len)
59 -{
60 - int i=0 ;
61 -
62 - if (!a_cur_tab)
63 - return 1 ;
64 - if (!a_saved_tab)
65 - return 0 ;
66 -
67 - for (i=0 ; i < a_tab_len; i++) {
68 - if (BuiltinDirRestore (&a_cur_tab[i], &a_saved_tab[i]))
69 - return 1 ;
70 - }
71 - return 0 ;
72 -}
73 -
74 -static BuiltinAliasPtr
75 -BuiltinAliasesDup (const BuiltinAliasPtr a_aliases,
76 - int a_aliases_len)
77 -{
78 - BuiltinAliasPtr aliases=NULL ;
79 - int i=0 ;
80 -
81 - if (!a_aliases)
82 - return NULL ;
83 -
84 - aliases = xcalloc (a_aliases_len, sizeof (BuiltinAliasRec)) ;
85 - if (!aliases)
86 - return NULL ;
87 -
88 - for (i=0; i < a_aliases_len; i++) {
89 - int len = strlen (a_aliases[i].font_name) ;
90 - aliases[i].font_name = xcalloc (1, len) ;
91 - memmove (aliases[i].font_name, a_aliases[i].font_name, len);
92 - }
93 - return aliases ;
94 -}
95 -
96 -/**
97 - * Copy a_save back into a_cur
98 - * @param a_cur the instance of BuiltinAlias to restore
99 - * @param a_saved the saved instance of BuiltinAlias to copy into a_cur
100 - * @return 0 if went okay, 1 otherwise.
101 - */
102 -static int
103 -BuiltinAliasRestore (BuiltinAliasPtr a_cur,
104 - const BuiltinAliasPtr a_save)
105 -{
106 - if (!a_cur)
107 - return 1 ;
108 - if (!a_save)
109 - return 0 ;
110 - if (a_save->alias_name)
111 - memmove (a_cur->alias_name, a_save->alias_name, strlen (a_save->alias_name)) ;
112 - if (a_save->font_name)
113 - memmove (a_cur->font_name, a_save->font_name, strlen (a_save->font_name)) ;
114 - return 0 ;
115 -}
116 -
117 -static int
118 -BuiltinAliasesRestore (BuiltinAliasPtr a_cur_tab,
119 - const BuiltinAliasPtr a_saved_tab,
120 - int a_tab_len)
121 -{
122 - int i=0 ;
123 -
124 - if (!a_cur_tab)
125 - return 1 ;
126 - if (!a_saved_tab)
127 - return 0 ;
128 -
129 - for (i=0 ; i < a_tab_len; i++) {
130 - if (BuiltinAliasRestore (&a_cur_tab[i], &a_saved_tab[i]))
131 - return 1 ;
132 - }
133 - return 0 ;
134 -}
135 -
136 int
137 BuiltinReadDirectory (char *directory, FontDirectoryPtr *pdir)
138 {
139 FontDirectoryPtr dir;
140 int i;
141
142 - static BuiltinDirPtr saved_builtin_dir;
143 - static BuiltinAliasPtr saved_builtin_alias;
144 + static char **builtin_dir_font_name_copy = NULL;
145
146 dir = FontFileMakeDir ("", builtin_dir_count);
147
148 - if (saved_builtin_dir)
149 - {
150 - BuiltinDirsRestore ((BuiltinDirPtr) builtin_dir,
151 - saved_builtin_dir,
152 - builtin_dir_count) ;
153 - }
154 - else
155 - {
156 - saved_builtin_dir = BuiltinDirsDup ((const BuiltinDirPtr) builtin_dir,
157 - builtin_dir_count) ;
158 - }
159 -
160 - if (saved_builtin_alias)
161 + if (!builtin_dir_font_name_copy)
162 {
163 - BuiltinAliasesRestore ((BuiltinAliasPtr) builtin_alias,
164 - saved_builtin_alias,
165 - builtin_alias_count) ;
166 + builtin_dir_font_name_copy = malloc (sizeof(char*) * builtin_dir_count);
167 + for (i = 0; i < builtin_dir_count; ++i)
168 + builtin_dir_font_name_copy[i] = strdup(builtin_dir[i].font_name);
169 }
170 else
171 {
172 - saved_builtin_alias = BuiltinAliasesDup ((const BuiltinAliasPtr) builtin_alias,
173 - builtin_alias_count) ;
174 + for (i = 0; i < builtin_dir_count; ++i)
175 + strcpy(builtin_dir_font_name_copy[i], builtin_dir[i].font_name);
176 }
177
178 for (i = 0; i < builtin_dir_count; i++)
179 {
180 if (!FontFileAddFontFile (dir,
181 - (char *) builtin_dir[i].font_name,
182 + (char *) builtin_dir_font_name_copy[i],
183 (char *) builtin_dir[i].file_name))
184 {
185 FontFileFreeDir (dir);