left = alloc_arg();
        right = alloc_arg();
 
+       if (!arg || !left || !right) {
+               do_warning("%s: not enough memory!", __func__);
+               /* arg will be freed at out_free */
+               free_arg(left);
+               free_arg(right);
+               goto out_free;
+       }
+
        arg->type = PRINT_OP;
        arg->op.left = left;
        arg->op.right = right;
        char *token = NULL;
 
        arg = alloc_arg();
+       if (!arg) {
+               do_warning("%s: not enough memory!", __func__);
+               /* '*tok' is set to top->op.op.  No need to free. */
+               *tok = NULL;
+               return EVENT_ERROR;
+       }
 
        *tok = NULL;
        type = process_arg(event, arg, &token);
 
                /* make an empty left */
                left = alloc_arg();
+               if (!left)
+                       goto out_warn_free;
+
                left->type = PRINT_NULL;
                arg->op.left = left;
 
                right = alloc_arg();
+               if (!right)
+                       goto out_warn_free;
+
                arg->op.right = right;
 
                /* do not free the token, it belongs to an op */
        } else if (strcmp(token, "?") == 0) {
 
                left = alloc_arg();
+               if (!left)
+                       goto out_warn_free;
+
                /* copy the top arg to the left */
                *left = *arg;
 
                   strcmp(token, "!=") == 0) {
 
                left = alloc_arg();
+               if (!left)
+                       goto out_warn_free;
 
                /* copy the top arg to the left */
                *left = *arg;
                        new_atom = realloc(left->atom.atom,
                                            strlen(left->atom.atom) + 3);
                        if (!new_atom)
-                               goto out_free;
+                               goto out_warn_free;
 
                        left->atom.atom = new_atom;
                        strcat(left->atom.atom, " *");
                }
 
                right = alloc_arg();
+               if (!right)
+                       goto out_warn_free;
+
                type = process_arg_token(event, right, tok, type);
                arg->op.right = right;
 
        } else if (strcmp(token, "[") == 0) {
 
                left = alloc_arg();
+               if (!left)
+                       goto out_warn_free;
+
                *left = *arg;
 
                arg->type = PRINT_OP;
 
        return type;
 
- out_free:
+out_warn_free:
+       do_warning("%s: not enough memory!", __func__);
+out_free:
        free_token(token);
        *tok = NULL;
        return EVENT_ERROR;
                        break;
 
                arg = alloc_arg();
+               if (!arg)
+                       goto out_free;
 
                free_token(token);
                type = process_arg(event, arg, &token);
 
                free_arg(arg);
                arg = alloc_arg();
+               if (!arg)
+                       goto out_free;
 
                free_token(token);
                type = process_arg(event, arg, &token);
        arg->type = PRINT_FLAGS;
 
        field = alloc_arg();
+       if (!field) {
+               do_warning("%s: not enough memory!", __func__);
+               goto out_free;
+       }
 
        type = process_arg(event, field, &token);
 
        arg->type = PRINT_SYMBOL;
 
        field = alloc_arg();
+       if (!field) {
+               do_warning("%s: not enough memory!", __func__);
+               goto out_free;
+       }
 
        type = process_arg(event, field, &token);
        if (test_type_token(type, token, EVENT_DELIM, ","))
        arg->type = PRINT_HEX;
 
        field = alloc_arg();
+       if (!field) {
+               do_warning("%s: not enough memory!", __func__);
+               goto out_free;
+       }
+
        type = process_arg(event, field, &token);
 
        if (test_type_token(type, token, EVENT_DELIM, ","))
        free_token(token);
 
        field = alloc_arg();
+       if (!field) {
+               do_warning("%s: not enough memory!", __func__);
+               *tok = NULL;
+               return EVENT_ERROR;
+       }
+
        type = process_arg(event, field, &token);
 
        if (test_type_token(type, token, EVENT_DELIM, ")"))
 
        free_token(token);
        arg = alloc_arg();
+       if (!field) {
+               do_warning("%s: not enough memory!", __func__);
+               *tok = NULL;
+               return EVENT_ERROR;
+       }
+
        type = process_arg(event, arg, &token);
        if (type == EVENT_ERROR)
                goto out_free_arg;
                }
 
                item_arg = alloc_arg();
+               if (!item_arg) {
+                       do_warning("%s: not enough memory!", __func__);
+                       goto out_free;
+               }
 
                arg->type = PRINT_TYPE;
                arg->typecast.type = arg->atom.atom;
        next_arg = &(arg->func.args);
        for (i = 0; i < func->nr_args; i++) {
                farg = alloc_arg();
+               if (!farg) {
+                       do_warning("%s: not enough memory!", __func__);
+                       return EVENT_ERROR;
+               }
+
                type = process_arg(event, farg, &token);
                if (i < (func->nr_args - 1))
                        test = ",";
                }
 
                arg = alloc_arg();
+               if (!arg) {
+                       do_warning("%s: not enough memory!", __func__);
+                       return -1;
+               }
 
                type = process_arg(event, arg, &token);
 
         * The first arg is the IP pointer.
         */
        args = alloc_arg();
+       if (!args) {
+               do_warning("%s(%d): not enough memory!", __func__, __LINE__);
+               return NULL;
+       }
        arg = args;
        arg->next = NULL;
        next = &arg->next;
                                val = pevent_read_number(pevent, bptr, vsize);
                                bptr += vsize;
                                arg = alloc_arg();
+                               if (!arg) {
+                                       do_warning("%s(%d): not enough memory!",
+                                                  __func__, __LINE__);
+                                       goto out_free;
+                               }
                                arg->next = NULL;
                                arg->type = PRINT_ATOM;
                                if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
                                break;
                        case 's':
                                arg = alloc_arg();
+                               if (!arg) {
+                                       do_warning("%s(%d): not enough memory!",
+                                                  __func__, __LINE__);
+                                       goto out_free;
+                               }
                                arg->next = NULL;
                                arg->type = PRINT_BSTRING;
                                arg->string.string = strdup(bptr);
                list = &event->print_fmt.args;
                for (field = event->format.fields; field; field = field->next) {
                        arg = alloc_arg();
+                       if (!arg) {
+                               event->flags |= EVENT_FL_FAILED;
+                               return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED;
+                       }
                        arg->type = PRINT_FIELD;
                        arg->field.name = strdup(field->name);
                        if (!arg->field.name) {