Commit a64e970809ffef749a155616e62d21802a374bd3

Ran Benita 2012-03-02T15:56:03

Remove unneeded freeing mechanisms Signed-off-by: Ran Benita <ran234@gmail.com>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
diff --git a/src/alloc.c b/src/alloc.c
index c677967..76fc40f 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -87,7 +87,7 @@ XkbcAllocCompatMap(struct xkb_desc * xkb, unsigned which, unsigned nSI)
 
 
 static void
-XkbcFreeCompatMap(struct xkb_desc * xkb, unsigned which, Bool freeMap)
+XkbcFreeCompatMap(struct xkb_desc * xkb)
 {
     struct xkb_compat_map * compat;
 
@@ -95,23 +95,10 @@ XkbcFreeCompatMap(struct xkb_desc * xkb, unsigned which, Bool freeMap)
         return;
 
     compat = xkb->compat;
-    if (freeMap)
-        which = XkbAllCompatMask;
 
-    if (which & XkbGroupCompatMask)
-        memset(&compat->groups[0], 0,
-               XkbNumKbdGroups * sizeof(struct xkb_mods));
-
-    if (which & XkbSymInterpMask) {
-        free(compat->sym_interpret);
-        compat->size_si = compat->num_si = 0;
-        compat->sym_interpret = NULL;
-    }
-
-    if (freeMap) {
-        free(compat);
-        xkb->compat = NULL;
-    }
+    free(compat->sym_interpret);
+    free(compat);
+    xkb->compat = NULL;
 }
 
 int
@@ -202,53 +189,32 @@ XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalRG, int nTotalAl
 }
 
 static void
-XkbcFreeNames(struct xkb_desc * xkb, unsigned which, Bool freeMap)
+XkbcFreeNames(struct xkb_desc * xkb)
 {
     struct xkb_names * names;
+    struct xkb_client_map * map;
 
     if (!xkb || !xkb->names)
         return;
 
     names = xkb->names;
-    if (freeMap)
-        which = XkbAllNamesMask;
+    map = xkb->map;
 
-    if (which & XkbKTLevelNamesMask) {
-        struct xkb_client_map * map = xkb->map;
-
-        if (map && map->types) {
-            int i;
-            struct xkb_key_type * type = map->types;
+    if (map && map->types) {
+        int i;
+        struct xkb_key_type * type = map->types;
 
-            for (i = 0; i < map->num_types; i++, type++) {
-                free(type->level_names);
-                type->level_names = NULL;
-            }
+        for (i = 0; i < map->num_types; i++, type++) {
+            free(type->level_names);
+            type->level_names = NULL;
         }
     }
 
-    if (which & XkbKeyNamesMask) {
-        free(names->keys);
-        names->keys = NULL;
-        names->num_keys = 0;
-    }
-
-    if (which & XkbKeyAliasesMask) {
-        free(names->key_aliases);
-        names->key_aliases = NULL;
-        names->num_key_aliases = 0;
-    }
-
-    if (which & XkbRGNamesMask) {
-        free(names->radio_groups);
-        names->radio_groups = NULL;
-        names->num_rg = 0;
-    }
-
-    if (freeMap) {
-        free(names);
-        xkb->names = NULL;
-    }
+    free(names->keys);
+    free(names->key_aliases);
+    free(names->radio_groups);
+    free(names);
+    xkb->names = NULL;
 }
 
 int
@@ -274,9 +240,9 @@ XkbcAllocControls(struct xkb_desc * xkb, unsigned which)
 }
 
 static void
-XkbcFreeControls(struct xkb_desc * xkb, unsigned which, Bool freeMap)
+XkbcFreeControls(struct xkb_desc * xkb)
 {
-    if (freeMap && xkb && xkb->ctrls) {
+    if (xkb && xkb->ctrls) {
         free(xkb->ctrls->per_key_repeat);
         free(xkb->ctrls);
         xkb->ctrls = NULL;
@@ -319,28 +285,17 @@ XkbcAllocKeyboard(void)
 }
 
 void
-XkbcFreeKeyboard(struct xkb_desc * xkb, unsigned which, Bool freeAll)
+XkbcFreeKeyboard(struct xkb_desc * xkb)
 {
     if (!xkb)
         return;
 
-    if (freeAll)
-        which = XkbAllComponentsMask;
-
-    if (which & XkbClientMapMask)
-        XkbcFreeClientMap(xkb, XkbAllClientInfoMask, True);
-    if (which & XkbServerMapMask)
-        XkbcFreeServerMap(xkb, XkbAllServerInfoMask, True);
-    if (which & XkbCompatMapMask)
-        XkbcFreeCompatMap(xkb, XkbAllCompatMask, True);
-    if (which & XkbIndicatorMapMask)
-        XkbcFreeIndicatorMaps(xkb);
-    if (which & XkbNamesMask)
-        XkbcFreeNames(xkb, XkbAllNamesMask, True);
-    if ((which & XkbGeometryMask) && xkb->geom)
-        XkbcFreeGeometry(xkb->geom, XkbGeomAllMask, True);
-    if (which & XkbControlsMask)
-        XkbcFreeControls(xkb, XkbAllControlsMask, True);
-    if (freeAll)
-        free(xkb);
+    XkbcFreeClientMap(xkb);
+    XkbcFreeServerMap(xkb);
+    XkbcFreeCompatMap(xkb);
+    XkbcFreeIndicatorMaps(xkb);
+    XkbcFreeNames(xkb);
+    XkbcFreeGeometry(xkb);
+    XkbcFreeControls(xkb);
+    free(xkb);
 }
diff --git a/src/galloc.c b/src/galloc.c
index e33e37d..34304cb 100644
--- a/src/galloc.c
+++ b/src/galloc.c
@@ -31,87 +31,37 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "XKBcommonint.h"
 #include <X11/extensions/XKB.h>
 
-static void
-_XkbFreeGeomLeafElems(Bool freeAll, int first, int count,
-                      unsigned short *num_inout, unsigned short *sz_inout,
-                      char **elems, unsigned int elem_sz)
-{
-    if (freeAll || !(*elems)) {
-        *num_inout = *sz_inout = 0;
-        free(*elems);
-        *elems = NULL;
-        return;
-    }
-
-    if ((first >= (*num_inout)) || (first < 0) || (count < 1))
-        return;
-
-    if (first + count >= (*num_inout))
-        /* truncating the array is easy */
-        (*num_inout) = first;
-    else {
-        char *ptr = *elems;
-        int extra = ((*num_inout) - first + count) * elem_sz;
-
-        if (extra > 0)
-            memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz],
-                    extra);
-
-        (*num_inout) -= count;
-    }
-}
-
-typedef void (*ContentsClearFunc)(char *priv);
+typedef void (*ContentsClearFunc)(void *priv);
 
 static void
-_XkbFreeGeomNonLeafElems(Bool freeAll, int first, int count,
-                         unsigned short *num_inout, unsigned short *sz_inout,
-                         char **elems, unsigned int elem_sz,
+_XkbFreeGeomNonLeafElems(unsigned short *num_inout, unsigned short *sz_inout,
+                         void *elems, size_t elem_sz,
                          ContentsClearFunc freeFunc)
 {
     int i;
-    char *ptr;
+    char *start, *ptr;
 
-    if (freeAll) {
-        first = 0;
-        count = *num_inout;
-    }
-    else if ((first >= (*num_inout)) || (first < 0) || (count < 1))
+    if (!elems)
         return;
-    else if (first + count > (*num_inout))
-        count = (*num_inout) - first;
 
-    if (!(*elems))
+    start = *(char **)elems;
+    if (!start)
         return;
 
-    if (freeFunc) {
-        ptr = *elems;
-        ptr += first * elem_sz;
-        for (i = 0; i < count; i++) {
-            (*freeFunc)(ptr);
-            ptr += elem_sz;
-        }
+    ptr = start;
+    for (i = 0; i < *num_inout; i++) {
+        freeFunc(ptr);
+        ptr += elem_sz;
     }
 
-    if (freeAll) {
-        *num_inout = *sz_inout = 0;
-        free(*elems);
-        *elems = NULL;
-    }
-    else if (first + count >= (*num_inout))
-        *num_inout = first;
-    else {
-        i = ((*num_inout) - first + count) * elem_sz;
-        ptr = *elems;
-        memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], i);
-        (*num_inout) -= count;
-    }
+    *num_inout = *sz_inout = 0;
+    free(start);
 }
 
 static void
-_XkbClearProperty(char *prop_in)
+_XkbClearProperty(void *prop_in)
 {
-    struct xkb_property * prop = (struct xkb_property *)prop_in;
+    struct xkb_property * prop = prop_in;
 
     free(prop->name);
     prop->name = NULL;
@@ -120,118 +70,80 @@ _XkbClearProperty(char *prop_in)
 }
 
 static void
-XkbcFreeGeomProperties(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomProperties(struct xkb_geometry * geom)
 {
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &geom->num_properties, &geom->sz_properties,
-                             (char **)&geom->properties,
-                             sizeof(struct xkb_property),
+    _XkbFreeGeomNonLeafElems(&geom->num_properties, &geom->sz_properties,
+                             &geom->properties, sizeof(struct xkb_property),
                              _XkbClearProperty);
 }
 
 static void
-XkbcFreeGeomKeyAliases(struct xkb_geometry * geom, int first, int count, Bool freeAll)
-{
-    _XkbFreeGeomLeafElems(freeAll, first, count,
-                          &geom->num_key_aliases, &geom->sz_key_aliases,
-                          (char **)&geom->key_aliases,
-                          sizeof(struct xkb_key_alias));
-}
-
-static void
-_XkbClearColor(char *color_in)
+_XkbClearColor(void *color_in)
 {
-    struct xkb_color * color = (struct xkb_color *)color_in;
+    struct xkb_color * color = color_in;
 
     free(color->spec);
 }
 
 static void
-XkbcFreeGeomColors(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomColors(struct xkb_geometry * geom)
 {
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &geom->num_colors, &geom->sz_colors,
-                             (char **)&geom->colors, sizeof(struct xkb_color),
+    _XkbFreeGeomNonLeafElems(&geom->num_colors, &geom->sz_colors,
+                             &geom->colors, sizeof(struct xkb_color),
                              _XkbClearColor);
 }
 
 static void
-XkbcFreeGeomPoints(struct xkb_outline * outline, int first, int count, Bool freeAll)
+_XkbClearOutline(void *outline_in)
 {
-    _XkbFreeGeomLeafElems(freeAll, first, count,
-                          &outline->num_points, &outline->sz_points,
-                          (char **)&outline->points, sizeof(struct xkb_point));
-}
-
-static void
-_XkbClearOutline(char *outline_in)
-{
-    struct xkb_outline * outline = (struct xkb_outline *)outline_in;
+    struct xkb_outline * outline = outline_in;
 
-    if (outline->points)
-        XkbcFreeGeomPoints(outline, 0, outline->num_points, True);
+    free(outline->points);
 }
 
 static void
-XkbcFreeGeomOutlines(struct xkb_shape * shape, int first, int count, Bool freeAll)
+XkbcFreeGeomOutlines(struct xkb_shape * shape)
 {
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &shape->num_outlines, &shape->sz_outlines,
-                             (char **)&shape->outlines, sizeof(struct xkb_outline),
+    _XkbFreeGeomNonLeafElems(&shape->num_outlines, &shape->sz_outlines,
+                             &shape->outlines, sizeof(struct xkb_outline),
                              _XkbClearOutline);
 }
 
 static void
-_XkbClearShape(char *shape_in)
+_XkbClearShape(void *shape_in)
 {
-    struct xkb_shape * shape = (struct xkb_shape *)shape_in;
+    struct xkb_shape * shape = shape_in;
 
-    if (shape->outlines)
-        XkbcFreeGeomOutlines(shape, 0, shape->num_outlines, True);
+    XkbcFreeGeomOutlines(shape);
 }
 
 static void
-XkbcFreeGeomShapes(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomShapes(struct xkb_geometry * geom)
 {
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &geom->num_shapes, &geom->sz_shapes,
-                             (char **)&geom->shapes, sizeof(struct xkb_shape),
+    _XkbFreeGeomNonLeafElems(&geom->num_shapes, &geom->sz_shapes,
+                             &geom->shapes, sizeof(struct xkb_shape),
                              _XkbClearShape);
 }
 
 static void
-XkbcFreeGeomKeys(struct xkb_row * row, int first, int count, Bool freeAll)
+_XkbClearRow(void *row_in)
 {
-    _XkbFreeGeomLeafElems(freeAll, first, count,
-                          &row->num_keys, &row->sz_keys,
-                          (char **)&row->keys, sizeof(struct xkb_key));
-}
+    struct xkb_row * row = row_in;
 
-static void
-_XkbClearRow(char *row_in)
-{
-    struct xkb_row * row = (struct xkb_row *)row_in;
-
-    if (row->keys)
-        XkbcFreeGeomKeys(row, 0, row->num_keys, True);
+    free(row->keys);
 }
 
 static void
-XkbcFreeGeomRows(struct xkb_section * section, int first, int count, Bool freeAll)
+XkbcFreeGeomRows(struct xkb_section * section)
 {
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &section->num_rows, &section->sz_rows,
-                             (char **)&section->rows, sizeof(struct xkb_row),
+    _XkbFreeGeomNonLeafElems(&section->num_rows, &section->sz_rows,
+                             &section->rows, sizeof(struct xkb_row),
                              _XkbClearRow);
 }
 
-
-
 static void
-_XkbClearDoodad(char *doodad_in)
+_XkbClearDoodad(union xkb_doodad *doodad)
 {
-    union xkb_doodad * doodad = (union xkb_doodad *)doodad_in;
-
     switch (doodad->any.type) {
     case XkbTextDoodad:
         free(doodad->text.text);
@@ -248,72 +160,52 @@ _XkbClearDoodad(char *doodad_in)
 }
 
 static void
-XkbcFreeGeomDoodads(union xkb_doodad * doodads, int nDoodads, Bool freeAll)
+XkbcFreeGeomDoodads(union xkb_doodad * doodads, int nDoodads)
 {
     int i;
     union xkb_doodad * doodad;
 
     for (i = 0, doodad = doodads; i < nDoodads && doodad; i++, doodad++)
-        _XkbClearDoodad((char *)doodad);
-    if (freeAll)
-        free(doodads);
+        _XkbClearDoodad(doodad);
+    free(doodads);
 }
 
 static void
-_XkbClearSection(char *section_in)
+_XkbClearSection(void *section_in)
 {
-    struct xkb_section * section = (struct xkb_section *)section_in;
+    struct xkb_section * section = section_in;
 
-    if (section->rows)
-        XkbcFreeGeomRows(section, 0, section->num_rows, True);
-    XkbcFreeGeomDoodads(section->doodads, section->num_doodads, True);
+    XkbcFreeGeomRows(section);
+    XkbcFreeGeomDoodads(section->doodads, section->num_doodads);
     section->doodads = NULL;
 }
 
 static void
-XkbcFreeGeomSections(struct xkb_geometry * geom, int first, int count, Bool freeAll)
+XkbcFreeGeomSections(struct xkb_geometry * geom)
 {
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &geom->num_sections, &geom->sz_sections,
-                             (char **)&geom->sections, sizeof(struct xkb_section),
+    _XkbFreeGeomNonLeafElems(&geom->num_sections, &geom->sz_sections,
+                             &geom->sections, sizeof(struct xkb_section),
                              _XkbClearSection);
 }
 
 void
-XkbcFreeGeometry(struct xkb_geometry * geom, unsigned which, Bool freeMap)
+XkbcFreeGeometry(struct xkb_desc * xkb)
 {
-    if (!geom)
-        return;
-
-    if (freeMap)
-        which = XkbGeomAllMask;
-
-    if ((which & XkbGeomPropertiesMask) && geom->properties)
-        XkbcFreeGeomProperties(geom, 0, geom->num_properties, True);
-
-    if ((which & XkbGeomColorsMask) && geom->colors)
-        XkbcFreeGeomColors(geom, 0, geom->num_colors, True);
-
-    if ((which & XkbGeomShapesMask) && geom->shapes)
-        XkbcFreeGeomShapes(geom, 0, geom->num_shapes, True);
+    struct xkb_geometry *geom;
 
-    if ((which & XkbGeomSectionsMask) && geom->sections)
-        XkbcFreeGeomSections(geom, 0, geom->num_sections, True);
-
-    if ((which & XkbGeomDoodadsMask) && geom->doodads) {
-        XkbcFreeGeomDoodads(geom->doodads, geom->num_doodads, True);
-        geom->doodads = NULL;
-        geom->num_doodads = geom->sz_doodads = 0;
-    }
+    if (!xkb || !xkb->geom)
+        return;
 
-    if ((which & XkbGeomKeyAliasesMask) && geom->key_aliases)
-        XkbcFreeGeomKeyAliases(geom, 0, geom->num_key_aliases, True);
+    geom = xkb->geom;
 
-    if (freeMap) {
-        free(geom->label_font);
-        geom->label_font = NULL;
-        free(geom);
-    }
+    XkbcFreeGeomProperties(geom);
+    XkbcFreeGeomColors(geom);
+    XkbcFreeGeomShapes(geom);
+    XkbcFreeGeomSections(geom);
+    XkbcFreeGeomDoodads(geom->doodads, geom->num_doodads);
+    free(geom->key_aliases);
+    free(geom->label_font);
+    free(geom);
 }
 
 static int
@@ -447,7 +339,7 @@ XkbcAllocGeometry(struct xkb_desc * xkb, struct xkb_geometry_sizes * sizes)
 
     return Success;
 bail:
-    XkbcFreeGeometry(geom, XkbGeomAllMask, True);
+    XkbcFreeGeometry(xkb);
     xkb->geom = NULL;
     return rtrn;
 }
diff --git a/src/malloc.c b/src/malloc.c
index 42e672f..737ad8b 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -380,91 +380,45 @@ XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed)
 }
 
 void
-XkbcFreeClientMap(struct xkb_desc * xkb, unsigned what, Bool freeMap)
+XkbcFreeClientMap(struct xkb_desc * xkb)
 {
+    int i;
     struct xkb_client_map * map;
+    struct xkb_key_type * type;
 
     if (!xkb || !xkb->map)
         return;
 
-    if (freeMap)
-        what = XkbAllClientInfoMask;
     map = xkb->map;
 
-    if (what & XkbKeyTypesMask) {
-        int i;
-        struct xkb_key_type * type;
-
-        for (i = 0, type = map->types; i < map->num_types && type; i++, type++) {
-            free(type->map);
-            type->map = NULL;
-            free(type->preserve);
-            type->preserve = NULL;
-            type->map_count = 0;
-            free(type->level_names);
-            type->level_names = NULL;
-        }
-        free(map->types);
-        map->num_types = map->size_types = 0;
-        map->types = NULL;
-    }
-
-    if (what & XkbKeySymsMask) {
-        free(map->key_sym_map);
-        map->key_sym_map = NULL;
-        free(map->syms);
-        map->size_syms = map->num_syms = 0;
-        map->syms = NULL;
-    }
-
-    if (what & XkbModifierMapMask) {
-        free(map->modmap);
-        map->modmap = NULL;
-    }
-
-    if (freeMap) {
-        free(xkb->map);
-        xkb->map = NULL;
+    for (i = 0, type = map->types; i < map->num_types && type; i++, type++) {
+        free(type->map);
+        free(type->preserve);
+        free(type->level_names);
     }
+    free(map->types);
+    free(map->key_sym_map);
+    free(map->syms);
+    free(map->modmap);
+    free(xkb->map);
+    xkb->map = NULL;
 }
 
 void
-XkbcFreeServerMap(struct xkb_desc * xkb, unsigned what, Bool freeMap)
+XkbcFreeServerMap(struct xkb_desc * xkb)
 {
     struct xkb_server_map * map;
 
     if (!xkb || !xkb->server)
         return;
 
-    if (freeMap)
-        what = XkbAllServerInfoMask;
     map = xkb->server;
 
-    if (what & XkbExplicitComponentsMask) {
-        free(map->explicit);
-        map->explicit = NULL;
-    }
-
-    if (what & XkbKeyActionsMask) {
-        free(map->key_acts);
-        map->key_acts = NULL;
-        free(map->acts);
-        map->num_acts = map->size_acts = 0;
-        map->acts = NULL;
-    }
-
-    if (what & XkbKeyBehaviorsMask) {
-        free(map->behaviors);
-        map->behaviors = NULL;
-    }
-
-    if (what & XkbVirtualModMapMask) {
-        free(map->vmodmap);
-        map->vmodmap = NULL;
-    }
-
-    if (freeMap) {
-        free(xkb->server);
-        xkb->server = NULL;
-    }
+    free(map->explicit);
+    free(map->key_acts);
+    free(map->acts);
+    free(map->behaviors);
+    free(map->vmodmap);
+    free(xkb->server);
+    xkb->server = NULL;
 }
diff --git a/src/maprules.c b/src/maprules.c
index 6d86ac1..d084e5b 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -979,7 +979,7 @@ XkbRF_ClearVarDescriptions(XkbRF_DescribeVarsPtr var)
 }
 
 void
-XkbcRF_Free(XkbRF_RulesPtr rules,Bool freeRules)
+XkbcRF_Free(XkbRF_RulesPtr rules)
 {
     int i;
     XkbRF_RulePtr rule;
@@ -996,8 +996,6 @@ XkbcRF_Free(XkbRF_RulesPtr rules,Bool freeRules)
 	    XkbRF_ClearVarDescriptions(&rules->extra[i]);
 	}
 	free(rules->extra);
-	rules->num_extra= rules->sz_extra= 0;
-	rules->extra= NULL;
     }
     for (i=0, rule = rules->rules; i < rules->num_rules && rules; i++, rule++) {
         free(rule->model);
@@ -1010,20 +1008,14 @@ XkbcRF_Free(XkbRF_RulesPtr rules,Bool freeRules)
         free(rule->compat);
         free(rule->geometry);
         free(rule->keymap);
-        memset(rule, 0, sizeof(XkbRF_RuleRec));
     }
     free(rules->rules);
-    rules->num_rules= rules->sz_rules= 0;
-    rules->rules= NULL;
 
     for (i=0, group = rules->groups; i < rules->num_groups && group; i++, group++) {
         free(group->name);
         free(group->words);
     }
     free(rules->groups);
-    rules->num_groups= 0;
-    rules->groups= NULL;
 
-    if (freeRules)
-	free(rules);
+    free(rules);
 }
diff --git a/src/xkballoc.h b/src/xkballoc.h
index 87762cb..56f4ad7 100644
--- a/src/xkballoc.h
+++ b/src/xkballoc.h
@@ -48,7 +48,7 @@ extern struct xkb_desc *
 XkbcAllocKeyboard(void);
 
 extern void
-XkbcFreeKeyboard(struct xkb_desc * xkb, unsigned which, Bool freeAll);
+XkbcFreeKeyboard(struct xkb_desc * xkb);
 
 /***====================================================================***/
 
@@ -68,9 +68,9 @@ extern union xkb_action *
 XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed);
 
 extern void
-XkbcFreeClientMap(struct xkb_desc * xkb, unsigned what, Bool freeMap);
+XkbcFreeClientMap(struct xkb_desc * xkb);
 
 extern void
-XkbcFreeServerMap(struct xkb_desc * xkb, unsigned what, Bool freeMap);
+XkbcFreeServerMap(struct xkb_desc * xkb);
 
 #endif /* _XKBALLOC_H_ */
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 45a385b..4298e60 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -83,7 +83,7 @@ XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs)
 
     if (!cached_name || strcmp(rules, cached_name) != 0) {
         if (loaded)
-            XkbcRF_Free(loaded, True);
+            XkbcRF_Free(loaded);
         loaded = NULL;
         free(cached_name);
         cached_name = NULL;
@@ -240,7 +240,7 @@ xkb_compile_keymap_from_components(const struct xkb_component_names * ktcsg)
 
     return xkb;
 unwind_xkb:
-    XkbcFreeKeyboard(xkb, XkbAllComponentsMask, True);
+    XkbcFreeKeyboard(xkb);
 unwind_file:
     /* XXX: here's where we would free the XkbFile */
 fail:
@@ -280,7 +280,7 @@ compile_keymap(XkbFile *file, const char *mapName)
 
     return xkb;
 unwind_xkb:
-    XkbcFreeKeyboard(xkb, XkbAllComponentsMask, True);
+    XkbcFreeKeyboard(xkb);
 unwind_file:
     /* XXX: here's where we would free the XkbFile */
 
@@ -328,5 +328,5 @@ xkb_compile_keymap_from_file(FILE *inputFile, const char *mapName)
 void
 xkb_free_keymap(struct xkb_desc *xkb)
 {
-       XkbcFreeKeyboard(xkb, 0, True);
+    XkbcFreeKeyboard(xkb);
 }
diff --git a/src/xkbgeom.h b/src/xkbgeom.h
index d0efcb7..6cb6e21 100644
--- a/src/xkbgeom.h
+++ b/src/xkbgeom.h
@@ -32,7 +32,7 @@ authorization from the authors.
 #include "xkbcommon/xkbcommon.h"
 
 extern void
-XkbcFreeGeometry(struct xkb_geometry * geom, unsigned which, Bool freeMap);
+XkbcFreeGeometry(struct xkb_desc * xkb);
 
 extern int
 XkbcAllocGeomKeyAliases(struct xkb_geometry * geom, int nKeyAliases);
diff --git a/src/xkbrules.h b/src/xkbrules.h
index 08c1c04..a69e8b9 100644
--- a/src/xkbrules.h
+++ b/src/xkbrules.h
@@ -156,6 +156,6 @@ extern Bool
 XkbcRF_LoadRules(FILE *file, XkbRF_RulesPtr rules);
 
 extern void
-XkbcRF_Free(XkbRF_RulesPtr rules, Bool freeRules);
+XkbcRF_Free(XkbRF_RulesPtr rules);
 
 #endif /* _XKBRULES_H_ */