radare2/libr/cmd/plugin.c
Fedor Sakharov 13547a0bbf Fix #370 - Some memory leaks
Fix memory leak in r_config_new.
  cfg->nodes->free should be a custom function that frees RConfigNode
  structure correctly, but not the ordinary free.
Fix memory leak in r_anal_new.
  In r_anal_free need to call r_meta_free to free the
  whole RMeta structure, not only it's data list.
  The r_meta_free doesn't seem to have any leak itself.
Fix leaking anal->hints.
Fix memory leaks in r_cmd_free
Fix memory leak in r_cmd_plugin_init
Fix memleak in r_lib_new
Fix memory leak in r_io_plugin_init
Fix memory leak in r_debug_trace_new
Fix memory leaks in r_io_new
Fix memory leak in r_graph_new
Fix memory leak in r_sys_getdir.
  Note: calling getcwd with dir=NULL is a Linux-specific extension
  of POSIX, not sure if works on other non-windows platforms.
Fixes a typo
2013-11-19 01:51:40 +01:00

59 lines
1.3 KiB
C

/* radare - LGPL - Copyright 2010-2012 - pancake */
/* covardly copied from r_cmd */
#include "../config.h"
#include <r_cmd.h>
#include <r_list.h>
#include <stdio.h>
static struct r_cmd_plugin_t *cmd_static_plugins[] =
{ R_CMD_STATIC_PLUGINS };
R_API int r_cmd_plugin_add(struct r_cmd_t *cmd, struct r_cmd_plugin_t *plugin) {
r_list_append (cmd->plist, plugin);
return R_TRUE;
}
R_API int r_cmd_plugin_init(struct r_cmd_t *cmd) {
int i;
RCmdPlugin *static_plugin;
cmd->plist = r_list_newf (free);
for (i=0; cmd_static_plugins[i]; i++) {
static_plugin = R_NEW (RCmdPlugin);
memcpy (static_plugin, cmd_static_plugins[i], sizeof (RCmdPlugin));
if (!r_cmd_plugin_add (cmd, static_plugin)) {
eprintf ("Error loading cmd plugin\n");
return R_FALSE;
}
}
return R_TRUE;
}
R_API int r_cmd_plugin_check(struct r_cmd_t *cmd, const char *a0) {
RListIter *iter;
RCmdPlugin *cp;
r_list_foreach (cmd->plist, iter, cp) {
if (cp->call (NULL, a0))
return R_TRUE;
}
return R_FALSE;
}
#if 0
// TODO: must return an r_iter ator
R_API int r_cmd_plugin_list(struct r_cmd_t *cmd) {
int n = 0;
struct list_head *pos;
cmd->printf ("IO plugins:\n");
list_for_each_prev(pos, &cmd->plist) {
struct r_cmd_list_t *il = list_entry(pos, struct r_cmd_list_t, list);
cmd->printf(" - %s\n", il->plugin->name);
n++;
}
return n;
}
#endif