Fix for segfault in top_name stuff.
[monky] / src / top.c
index d230679..29b169b 100644 (file)
--- a/src/top.c
+++ b/src/top.c
@@ -880,22 +880,22 @@ int parse_top_args(const char *s, const char *arg, struct text_object *obj)
 #else /* IOSTATS */
                        NORM_ERR("must be one of: name, cpu, pid, mem, time, mem_res, mem_vsize");
 #endif /* IOSTATS */
-                       free_and_zero(td->s);
-                       free_and_zero(obj->data.opaque);
+                       free(td->s);
+                       free(obj->data.opaque);
                        return 0;
                }
                if (n < 1 || n > 10) {
                        NORM_ERR("invalid num arg for top. Must be between 1 and 10.");
-                       free_and_zero(td->s);
-                       free_and_zero(obj->data.opaque);
+                       free(td->s);
+                       free(obj->data.opaque);
                        return 0;
                } else {
                        td->num = n - 1;
                }
        } else {
                NORM_ERR("invalid argument count for top");
-               free_and_zero(td->s);
-               free_and_zero(obj->data.opaque);
+               free(td->s);
+               free(obj->data.opaque);
                return 0;
        }
        return 1;
@@ -986,9 +986,11 @@ void print_top(struct text_object *obj, char *p, int p_max_size)
 
                switch (td->type) {
                        case TOP_NAME:
-                               width = MIN(p_max_size, (int)top_name_width + 1);
-                               snprintf(p, width + 1, "%-*s", width,
-                                               needed[td->num]->name);
+                               if (needed[td->num]->name) {
+                                       width = MIN(p_max_size, (int)top_name_width + 1);
+                                       snprintf(p, width + 1, "%-*s", width,
+                                                       needed[td->num]->name);
+                               }
                                break;
                        case TOP_CPU:
                                width = MIN(p_max_size, 7);