if (!op) {
                op = malloc(sizeof(*op));
                if (!op)
-                       return -ENOMEM;
+                       goto out_free;
                memset(op, 0, sizeof(*op));
-               op->next = trace_plugin_options;
-               trace_plugin_options = op;
-
                op->plugin = plugin;
                op->option = option_str;
-
                if (val) {
                        op->value = strdup(val);
-                       if (!op->value)
+                       if (!op->value) {
+                               free(op);
                                goto out_free;
+                       }
                }
+               op->next = trace_plugin_options;
+               trace_plugin_options = op;
        }
 
        return process_option(plugin, option_str, val);
- out_free:
+
+out_free:
+       free(plugin);
        free(option_str);
        return -ENOMEM;
 }