First step in making struct variable opaque: the boring mechanical
[pspp-builds.git] / src / data / category.c
index 55d7ca8b05addbe392424f1114755d9e4629645d..21506ed8b5d0af64b2d2dc0e538776d9db27a78e 100644 (file)
   'cat_var'.
 */
 #include <config.h>
+
+#include "category.h"
+
+#include <assert.h>
 #include <stdlib.h>
+#include <string.h>
+
 #include <libpspp/alloc.h>
 #include <libpspp/message.h>
-#include "category.h"
 #include "cat-routines.h"
-#include <string.h>
 #include "variable.h"
 
 #define N_INITIAL_CATEGORIES 1
@@ -59,9 +63,16 @@ void
 cat_stored_values_destroy (struct variable *v)
 {
   assert (v != NULL);
+
   if (v->obs_vals != NULL)
     {
+      if (v->obs_vals->n_allocated_categories > 0)
+       {
+         free (v->obs_vals->vals);
+         v->obs_vals->vals = NULL;
+       }
       free (v->obs_vals);
+      v->obs_vals = NULL;
     }
 }
 
@@ -81,7 +92,7 @@ cat_value_find (const struct variable *v, const union value *val)
     {
       candidate = v->obs_vals->vals + i;
       assert (candidate != NULL);
-      if (!compare_values (candidate, val, v->width))
+      if (!compare_values (candidate, val, var_get_width (v)))
        {
          return i;
        }
@@ -97,7 +108,7 @@ cat_value_update (struct variable *v, const union value *val)
 {
   struct cat_vals *cv;
 
-  if (v->type == ALPHA)
+  if (var_is_alpha (v))
     {
       assert (val != NULL);
       assert (v != NULL);