[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[597] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-12-22 12:47:35
|
Revision: 597 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=597&view=rev Author: nickols_k Date: 2012-12-22 12:47:25 +0000 (Sat, 22 Dec 2012) Log Message: ----------- memory leaks-- Modified Paths: -------------- mplayerxp/input2/input.cpp mplayerxp/libvo2/font_load.cpp mplayerxp/loader/registry.c mplayerxp/mplayerxp.cpp mplayerxp/nls/mpxp_help-en.h mplayerxp/nls/mpxp_help-ru.h mplayerxp/osdep/get_path.cpp mplayerxp/osdep/get_path.h mplayerxp/postproc/af_export.cpp mplayerxp/postproc/af_raw.cpp Modified: mplayerxp/input2/input.cpp =================================================================== --- mplayerxp/input2/input.cpp 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/input2/input.cpp 2012-12-22 12:47:25 UTC (rev 597) @@ -1127,7 +1127,7 @@ #define BS_MAX 256 #define SPACE_CHAR " \n\r\t" -static int mp_input_parse_config(libinput_t& priv,const char *file) { +static int mp_input_parse_config(libinput_t& priv,const std::string& file) { int fd; int bs = 0,r,eof = 0,comments = 0; char *iter,*end; @@ -1135,7 +1135,7 @@ int n_binds = 0, keys[MP_MAX_KEY_DOWN+1] = { 0 }; mp_cmd_bind_t* binds = NULL; - fd = open(file,O_RDONLY); + fd = ::open(file.c_str(),O_RDONLY); if(fd < 0) { mpxp_err<<"Can't open input config file "<<file<<" : "<<strerror(errno)<<std::endl; @@ -1266,14 +1266,14 @@ } static void mp_input_init(libinput_t& priv) { - const char* file; + std::string file; file = config_file[0] != '/' ? get_path(config_file) : config_file; - if(!file) return; + if(file.empty()) return; if(! mp_input_parse_config(priv,file)) { // Try global conf dir - file = CONFDIR "/input.conf"; + file = std::string(CONFDIR)+"/input.conf"; if(! mp_input_parse_config(priv,file)) mpxp_warn<<"Falling back on default (hardcoded) input config"<<std::endl; } #ifdef HAVE_JOYSTICK Modified: mplayerxp/libvo2/font_load.cpp =================================================================== --- mplayerxp/libvo2/font_load.cpp 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/libvo2/font_load.cpp 2012-12-22 12:47:25 UTC (rev 597) @@ -10,7 +10,6 @@ #include <unistd.h> #include "font_load.h" #include "sub.h" -#include "osdep/get_path.h" #include "vo_msg.h" raw_file* load_raw(const char *name,int verbose){ @@ -72,9 +71,6 @@ desc->fpath = dn; // search in the same dir as fonts.desc - // desc->fpath=get_path("font/"); - // if (stat(desc->fpath, &fstate)!=0) desc->fpath=DATADIR"/font"; - // set up some defaults, and erase table desc->charspace=2; desc->spacewidth=12; desc->height=0; Modified: mplayerxp/loader/registry.c =================================================================== --- mplayerxp/loader/registry.c 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/loader/registry.c 2012-12-22 12:47:25 UTC (rev 597) @@ -23,8 +23,27 @@ //#undef TRACE //#define TRACE printf -extern char *get_path ( char * ); +static char *get_path(const char *filename){ + char *homedir; + char *buff; + static const char *config_dir = "/."PROGNAME; + int len; + if ((homedir = getenv("HOME")) == NULL) + return NULL; + len = strlen(homedir) + strlen(config_dir) + 1; + if (filename == NULL) { + if ((buff = (char *) mp_malloc(len)) == NULL) + return NULL; + sprintf(buff, "%s%s", homedir, config_dir); + } else { + len += strlen(filename) + 1; + if ((buff = (char *) mp_malloc(len)) == NULL) + return NULL; + sprintf(buff, "%s%s/%s", homedir, config_dir, filename); + } + return buff; +} // ...can be set before init_registry() call char* regpathname = NULL; Modified: mplayerxp/mplayerxp.cpp =================================================================== --- mplayerxp/mplayerxp.cpp 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/mplayerxp.cpp 2012-12-22 12:47:25 UTC (rev 597) @@ -426,26 +426,23 @@ void parse_cfgfiles( m_config_t& conf ) { - char *conffile; + std::string conffile; int conffile_fd; - if ((conffile = get_path("")) == NULL) { - mpxp_warn<<MSGTR_NoHomeDir<<std::endl; - } else { - mkdir(conffile, 0777); - delete conffile; - if ((conffile = get_path("config")) == NULL) { + conffile = get_path(); + if (conffile.empty()) mpxp_warn<<MSGTR_NoHomeDir<<std::endl; + else { + ::mkdir(conffile.c_str(), 0777); + conffile = get_path("config"); + if (conffile.empty()) { mpxp_err<<MSGTR_GetpathProblem<<std::endl; - conffile=(char*)mp_malloc(strlen("config")+1); - if(conffile) - strcpy(conffile,"config"); + conffile="config"; } - if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) { + if ((conffile_fd = ::open(conffile.c_str(), O_CREAT | O_EXCL | O_WRONLY, 0666)) != -1) { mpxp_info<<MSGTR_CreatingCfgFile<<": "<<conffile<<std::endl; ::write(conffile_fd, default_config, strlen(default_config)); ::close(conffile_fd); } - if (m_config_parse_config_file(conf, conffile) != MPXP_Ok) exit(1); - delete conffile; + if (m_config_parse_config_file(conf, conffile.c_str()) != MPXP_Ok) exit(1); } } @@ -568,7 +565,7 @@ #ifdef ENABLE_WIN32LOADER /* check codec.conf*/ - if(!parse_codec_cfg(get_path("win32codecs.conf"))) { + if(!parse_codec_cfg(get_path("win32codecs.conf").c_str())) { if(!parse_codec_cfg(CONFDIR"/win32codecs.conf")) { mpxp_hint<<MSGTR_CopyCodecsConf<<std::endl; mpxp_uninit_structs(); @@ -614,7 +611,7 @@ afm_help(); #ifdef ENABLE_WIN32LOADER /* check codec.conf*/ - if(!parse_codec_cfg(get_path("win32codecs.conf"))){ + if(!parse_codec_cfg(get_path("win32codecs.conf").c_str())){ if(!parse_codec_cfg(CONFDIR"/win32codecs.conf")){ mpxp_hint<<MSGTR_CopyCodecsConf<<std::endl; mpxp_uninit_structs(); @@ -842,20 +839,20 @@ mpxp_err<<MSGTR_CantLoadFont<<": "<<mp_conf.font_name<<std::endl; } else { // try default: - mpxp_context().video().output->font=read_font_desc(get_path("font/font.desc"),mp_conf.font_factor,mp_conf.verbose>1); + mpxp_context().video().output->font=read_font_desc(get_path("font/font.desc").c_str(),mp_conf.font_factor,mp_conf.verbose>1); if(!mpxp_context().video().output->font) mpxp_context().video().output->font=read_font_desc(DATADIR"/font/font.desc",mp_conf.font_factor,mp_conf.verbose>1); } #endif /* Configure menu here */ { - const char *menu_cfg; + std::string menu_cfg; menu_cfg = get_path("menu.conf"); - if(menu_init(NULL, menu_cfg)) + if(menu_init(NULL, menu_cfg.c_str())) mpxp_info<<"Menu initialized: "<<menu_cfg<<std::endl; else { menu_cfg="/etc/menu.conf"; - if(menu_init(NULL, menu_cfg)) + if(menu_init(NULL, menu_cfg.c_str())) mpxp_info<<"Menu initialized: "<<menu_cfg<<std::endl; else mpxp_warn<<"Menu init failed"<<std::endl; @@ -1074,7 +1071,7 @@ mpxp_context().subtitles=sub_read_file(mp_conf.sub_name, sh_video->fps); if(!mpxp_context().subtitles) mpxp_err<<MSGTR_CantLoadSub<<": "<<mp_conf.sub_name<<std::endl; } else if(mp_conf.sub_auto) { // auto load sub file ... - mpxp_context().subtitles=sub_read_file( filename ? sub_filename( get_path("sub/"), filename ) + mpxp_context().subtitles=sub_read_file( filename ? sub_filename(get_path("sub/").c_str(), filename ) : "default.sub", sh_video->fps ); } if(mpxp_context().subtitles) { Modified: mplayerxp/nls/mpxp_help-en.h =================================================================== --- mplayerxp/nls/mpxp_help-en.h 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/nls/mpxp_help-en.h 2012-12-22 12:47:25 UTC (rev 597) @@ -100,7 +100,7 @@ #define MSGTR_IntBySignal "\nMPlayerXP interrupted by signal %d in module: %s \n" #endif #ifndef MSGTR_GetpathProblem -#define MSGTR_GetpathProblem "get_path(\"config\") problem\n" +#define MSGTR_GetpathProblem "get_path(\"config\") problem" #endif #ifndef MSGTR_CreatingCfgFile #define MSGTR_CreatingCfgFile "Creating config file" Modified: mplayerxp/nls/mpxp_help-ru.h =================================================================== --- mplayerxp/nls/mpxp_help-ru.h 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/nls/mpxp_help-ru.h 2012-12-22 12:47:25 UTC (rev 597) @@ -76,7 +76,7 @@ #define MSGTR_Playing "Воспроизведение" #define MSGTR_IntBySignal "\nMPlayerXP прерван сигналом %d в модуле: %s \n" -#define MSGTR_GetpathProblem "проблемы в get_path(\"config\")\n" +#define MSGTR_GetpathProblem "проблемы в get_path(\"config\")" #define MSGTR_CreatingCfgFile "Создание файла конфигурации" #define MSGTR_InvalidVOdriver "Недопустимое имя драйвера видео вывода" #define MSGTR_InvalidAOdriver "Недопустимое имя драйвера аудио вывода" Modified: mplayerxp/osdep/get_path.cpp =================================================================== --- mplayerxp/osdep/get_path.cpp 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/osdep/get_path.cpp 2012-12-22 12:47:25 UTC (rev 597) @@ -8,26 +8,15 @@ #include <string.h> #include "osdep_msg.h" namespace mpxp { -char *get_path(const char *filename){ - char *homedir; - char *buff; - static const char *config_dir = "/."PROGNAME; - int len; +std::string get_path(const std::string& filename){ + char *homedir; + std::string rs; + std::string config_dir = std::string("/.")+PROGNAME; - if ((homedir = getenv("HOME")) == NULL) - return NULL; - len = strlen(homedir) + strlen(config_dir) + 1; - if (filename == NULL) { - if ((buff = (char *) mp_malloc(len)) == NULL) - return NULL; - sprintf(buff, "%s%s", homedir, config_dir); - } else { - len += strlen(filename) + 1; - if ((buff = (char *) mp_malloc(len)) == NULL) - return NULL; - sprintf(buff, "%s%s/%s", homedir, config_dir, filename); - } - MSG_V("get_path('%s') -> '%s'\n",filename,buff); - return buff; + if ((homedir = ::getenv("HOME")) == NULL) return ""; + rs=std::string(homedir)+config_dir; + if (!filename.empty()) rs+="/"+filename; + mpxp_v<<"get_path('"<<filename<<"') -> "<<rs<<std::endl; + return rs; } }// namespace mpxp Modified: mplayerxp/osdep/get_path.h =================================================================== --- mplayerxp/osdep/get_path.h 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/osdep/get_path.h 2012-12-22 12:47:25 UTC (rev 597) @@ -1,7 +1,8 @@ #ifndef __MPXP_GET_PATH #define __MPXP_GET_PATH 1 +#include <string> namespace mpxp { - char *get_path(const char *filename); + std::string get_path(const std::string& filename=""); } #endif Modified: mplayerxp/postproc/af_export.cpp =================================================================== --- mplayerxp/postproc/af_export.cpp 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/postproc/af_export.cpp 2012-12-22 12:47:25 UTC (rev 597) @@ -26,8 +26,8 @@ #include "af.h" #include "af_internal.h" #include "mpxp_help.h" -#include "osdep/get_path.h" #include "osdep/fastmemcpy.h" +#include "osdep/get_path.h" #include "pp_msg.h" #define DEF_SZ 512 // default buffer size (in samples) @@ -41,11 +41,11 @@ { unsigned long long count; // Used for sync uint8_t* buf[AF_NCH]; // Buffers for storing the data before it is exported - int sz; // Size of buffer in samples - int wi; // Write index - int fd; // File descriptor to shared memory area - char* filename; // File to export data - any_t* mmap_area; // MMap shared area + int sz; // Size of buffer in samples + int wi; // Write index + int fd; // File descriptor to shared memory area + std::string filename; // File to export data + any_t* mmap_area; // MMap shared area }; /* Initialization and runtime control_af @@ -81,17 +81,15 @@ // Allocate new buffers (as one continuous block) s->buf[0] = new(zeromem) uint8_t[s->sz*af->conf.nch*af->conf.format&MPAF_BPS_MASK]; - if(NULL == s->buf[0]) - MSG_FATAL(MSGTR_OutOfMemory); + if(NULL == s->buf[0]) mpxp_fatal<<MSGTR_OutOfMemory<<std::endl; for(i = 1; i < af->conf.nch; i++) s->buf[i] = s->buf[0] + i*s->sz*(af->conf.format&MPAF_BPS_MASK); // Init memory mapping - s->fd = open(s->filename, O_RDWR | O_CREAT | O_TRUNC, 0640); - MSG_INFO( "[export] Exporting to file: %s\n", s->filename); + s->fd = open(s->filename.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0640); + mpxp_info<<"[export] Exporting to file: "<<s->filename<<std::endl; if(s->fd < 0) - MSG_FATAL( "[export] Could not open/create file: %s\n", - s->filename); + mpxp_fatal<<"[export] Could not open/create file: "<<s->filename<<std::endl; // header + buffer mapsize = (SIZE_HEADER + ((af->conf.format&MPAF_BPS_MASK) * s->sz * af->conf.nch)); @@ -105,9 +103,8 @@ // mmap size s->mmap_area = mmap(0, mapsize, PROT_READ|PROT_WRITE,MAP_SHARED, s->fd, 0); if(s->mmap_area == NULL) - MSG_FATAL( "[export] Could not mmap file %s\n", s->filename); - MSG_INFO( "[export] Memory mapped to file: %s (%p)\n", - s->filename, s->mmap_area); + mpxp_fatal<<"[export] Could not mmap file "<<s->filename<<std::endl; + mpxp_info<<"[export] Memory mapped to file: "<<s->filename<<std::endl; // Initialize header *((int*)s->mmap_area) = af->conf.nch; @@ -127,9 +124,6 @@ char *str = reinterpret_cast<char*>(arg); if (!str){ - if(s->filename) - delete s->filename; - s->filename = get_path(SHARED_FILE); return MPXP_Ok; } @@ -137,13 +131,7 @@ while((str[i]) && (str[i] != ':')) i++; - if(s->filename) - delete s->filename; - - s->filename = new(zeromem) char[i + 1]; - memcpy(s->filename, str, i); - s->filename[i] = 0; - + s->filename.assign(str, i); sscanf(str + i + 1, "%d", &(s->sz)); return af->control_af(af, AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET, &s->sz); @@ -151,8 +139,7 @@ case AF_CONTROL_EXPORT_SZ | AF_CONTROL_SET: s->sz = * (int *) arg; if((s->sz <= 0) || (s->sz > 2048)) - MSG_ERR( "[export] Buffer size must be between" - " 1 and 2048\n" ); + mpxp_err<<"[export] Buffer size must be between 1 and 2048"<<std::endl; return MPXP_Ok; case AF_CONTROL_EXPORT_SZ | AF_CONTROL_GET: @@ -180,9 +167,6 @@ if(s->fd > -1) close(s->fd); - if(s->filename) - delete s->filename; - delete s; af->setup = NULL; } Modified: mplayerxp/postproc/af_raw.cpp =================================================================== --- mplayerxp/postproc/af_raw.cpp 2012-12-22 12:17:38 UTC (rev 596) +++ mplayerxp/postproc/af_raw.cpp 2012-12-22 12:47:25 UTC (rev 597) @@ -20,7 +20,6 @@ #include "af.h" #include "af_internal.h" #include "mpxp_help.h" -#include "osdep/get_path.h" #include "pp_msg.h" #define WAV_ID_RIFF 0x46464952 /* "RIFF" */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |