Index: apps/plugin.c =================================================================== --- apps/plugin.c (revision 24144) +++ apps/plugin.c (working copy) @@ -63,6 +63,15 @@ #define PREFIX #endif +#ifndef SIMULATOR +#if MAX_OPEN_FILES>32 +#warning "MAX_OPEN_FILES>32, disabling plugin file open/close checking" +#else +#define CHECK_OPEN_CLOSE +static unsigned int open_files; +#endif +#endif + #ifdef SIMULATOR static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE]; void *sim_plugin_load(char *plugin, void **pd); @@ -83,6 +92,12 @@ char *plugin_get_current_filename(void); +/* Some wrappers */ +static int open_wrapper(const char* pathname, int flags); +static int close_wrapper(int fd); +static int creat_wrapper(const char *pathname); + + static const struct plugin_api rockbox_api = { /* lcd */ @@ -276,11 +291,11 @@ #endif /* HAVE_BUTTON_LIGHT */ /* file */ - (open_func)PREFIX(open), - PREFIX(close), + (open_func)open_wrapper, + close_wrapper, (read_func)PREFIX(read), PREFIX(lseek), - (creat_func)PREFIX(creat), + (creat_func)creat_wrapper, (write_func)PREFIX(write), PREFIX(remove), PREFIX(rename), @@ -804,8 +819,12 @@ touchscreen_set_mode(TOUCHSCREEN_BUTTON); #endif +#ifdef CHECK_OPEN_CLOSE + open_files = 0; +#endif + rc = hdr->entry_point(parameter); - + /* Go back to the global setting in case the plugin changed it */ #ifdef HAVE_TOUCHSCREEN touchscreen_set_mode(global_settings.touch_mode); @@ -849,6 +868,21 @@ if (pfn_tsr_exit == NULL) plugin_loaded = false; +#ifdef CHECK_OPEN_CLOSE + if(open_files != 0 && !plugin_loaded) + { + int fd; + logf("Plugin '%s' leaks filehandles",plugin); + for(fd=0;fd=0) open_files |= (1<=0) open_files &= (~(1<=0) open_files |= (1<