mpcinfo: Fix memory leaks

Closes #1838
This commit is contained in:
Igor 2016-10-11 13:34:29 +03:00 committed by Patrick Griffis
parent 2a81b98e7b
commit f38261f666
3 changed files with 17 additions and 8 deletions

View File

@ -122,7 +122,6 @@ struct tagInfo readID3V1(char *file){
char *tag; char *tag;
char *id; char *id;
char *tmp; char *tmp;
tag = (char*) malloc(sizeof(char)*129);
ret.artist=NULL; ret.artist=NULL;
f=fopen(file,"rb"); f=fopen(file,"rb");
if (f==NULL){ if (f==NULL){
@ -133,18 +132,21 @@ struct tagInfo readID3V1(char *file){
//int offset=getSize(file)-128; //int offset=getSize(file)-128;
res=fseek(f,-128,SEEK_END); res=fseek(f,-128,SEEK_END);
if (res!=0) {printf("seek failed\n");fclose(f);return ret;} if (res!=0) {printf("seek failed\n");fclose(f);return ret;}
tag = (char*) malloc(sizeof(char)*129);
//long int pos=ftell(f); //long int pos=ftell(f);
//printf("position= %li\n",pos); //printf("position= %li\n",pos);
for (i=0;i<128;i++) { for (i=0;i<128;i++) {
c=fgetc(f); c=fgetc(f);
if (c==EOF) {hexchat_printf(ph,"read ID3V1 failed\n");fclose(f);return ret;} if (c==EOF) {hexchat_printf(ph,"read ID3V1 failed\n");fclose(f);free(tag);return ret;}
tag[i]=(char)c; tag[i]=(char)c;
} }
fclose(f); fclose(f);
//printf("tag readed: \n"); //printf("tag readed: \n");
id=substring(tag,0,3); id=substring(tag,0,3);
//printf("header: %s\n",id); //printf("header: %s\n",id);
if (strcmp(id,"TAG")!=0){hexchat_printf(ph,"no id3 v1 found\n");return ret;} res=strcmp(id,"TAG");
free(id);
if (res!=0){hexchat_printf(ph,"no id3 v1 found\n");free(tag);return ret;}
ret.title=subString(tag,3,30,1); ret.title=subString(tag,3,30,1);
ret.artist=subString(tag,33,30,1); ret.artist=subString(tag,33,30,1);
ret.album=subString(tag,63,30,1); ret.album=subString(tag,63,30,1);
@ -164,6 +166,8 @@ struct tagInfo readID3V1(char *file){
//hexchat_printf(ph, "tmp: \"%s\" -> %i",tmp,tmp[0]); //hexchat_printf(ph, "tmp: \"%s\" -> %i",tmp,tmp[0]);
//hexchat_printf(ph,"genre \"%s\"",ret.genre); //hexchat_printf(ph,"genre \"%s\"",ret.genre);
//if (DEBUG==1) putlog("id3v1 extracted"); //if (DEBUG==1) putlog("id3v1 extracted");
free(tmp);
free(tag);
return ret; return ret;
} }

View File

@ -104,6 +104,7 @@ struct tagInfo getOggHeader(char *file){
if (strcmp(name,"GENRE")==0) info.genre=val; if (strcmp(name,"GENRE")==0) info.genre=val;
if (strcmp(name,"COMMENT")==0) info.comment=val; if (strcmp(name,"COMMENT")==0) info.comment=val;
pos+=4+tagLen; pos+=4+tagLen;
free(name);
} }
if (info.artist==NULL) info.artist=""; if (info.artist==NULL) info.artist="";
if (info.album==NULL) info.album =""; if (info.album==NULL) info.album ="";

View File

@ -91,13 +91,15 @@ struct theme themeAdd(struct theme data, char *info){
} }
void loadThemes(){ void loadThemes(){
char *hDir, *hFile, *line, *val; char *hDir, *hFile, *line, *lineCap, *val;
FILE *f; FILE *f;
hexchat_print(ph,"loading themes\n"); hexchat_print(ph,"loading themes\n");
hDir=(char*)calloc(1024,sizeof(char)); hDir=(char*)calloc(1024,sizeof(char));
strcpy(hDir,hexchat_get_info(ph,"configdir")); strcpy(hDir,hexchat_get_info(ph,"configdir"));
hFile=str3cat(hDir,"\\","mpcInfo.theme.txt"); hFile=str3cat(hDir,"\\","mpcInfo.theme.txt");
f = fopen(hFile,"r"); f = fopen(hFile,"r");
free(hDir);
free(hFile);
if(f==NULL) if(f==NULL)
{ {
hexchat_print(ph,"no theme in homedir, checking global theme"); hexchat_print(ph,"no theme in homedir, checking global theme");
@ -120,10 +122,12 @@ void loadThemes(){
val=split(line,'='); val=split(line,'=');
printf("line: %s\n",line); printf("line: %s\n",line);
printf("val: %s\n",val); printf("val: %s\n",val);
if (strcmp(toUpper(line),"OFF_LINE")==0) notRunTheme=themeAdd(notRunTheme,val); lineCap=toUpper(line);
if (strcmp(toUpper(line),"TITLE_LINE")==0) titleTheme=themeAdd(titleTheme,val); if (strcmp(lineCap,"OFF_LINE")==0) notRunTheme=themeAdd(notRunTheme,val);
if (strcmp(toUpper(line),"MP3_LINE")==0) mp3Theme=themeAdd(mp3Theme,val); if (strcmp(lineCap,"TITLE_LINE")==0) titleTheme=themeAdd(titleTheme,val);
if (strcmp(toUpper(line),"OGG_LINE")==0) mp3Theme=themeAdd(oggTheme,val); if (strcmp(lineCap,"MP3_LINE")==0) mp3Theme=themeAdd(mp3Theme,val);
if (strcmp(lineCap,"OGG_LINE")==0) mp3Theme=themeAdd(oggTheme,val);
free(lineCap);
} }
fclose(f); fclose(f);
hexchat_print(ph, "theme loaded successfull\n"); hexchat_print(ph, "theme loaded successfull\n");