summary refs log tree commit diff stats
path: root/plugins/mpcinfo/mp3Info.c
diff options
context:
space:
mode:
authorIgor <f2404@yandex.ru>2016-10-11 13:34:29 +0300
committerPatrick Griffis <tingping@tingping.se>2016-10-11 09:55:29 -0400
commitf38261f666a2e41bbd189940ca7d419b3e726376 (patch)
tree4129ce87ce3e2011b6b089d2f33ae8e5e8928430 /plugins/mpcinfo/mp3Info.c
parent2a81b98e7bcad05bf54d9c423f68df6492ae4326 (diff)
mpcinfo: Fix memory leaks
Closes #1838
Diffstat (limited to 'plugins/mpcinfo/mp3Info.c')
-rw-r--r--plugins/mpcinfo/mp3Info.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/plugins/mpcinfo/mp3Info.c b/plugins/mpcinfo/mp3Info.c
index 1af29e45..240b07a6 100644
--- a/plugins/mpcinfo/mp3Info.c
+++ b/plugins/mpcinfo/mp3Info.c
@@ -122,7 +122,6 @@ struct tagInfo readID3V1(char *file){
 	char *tag;
 	char *id;
 	char *tmp;
-	tag = (char*) malloc(sizeof(char)*129);
 	ret.artist=NULL;
 	f=fopen(file,"rb");
 	if (f==NULL){
@@ -133,18 +132,21 @@ struct tagInfo readID3V1(char *file){
 	//int offset=getSize(file)-128;
 	res=fseek(f,-128,SEEK_END);
 	if (res!=0) {printf("seek failed\n");fclose(f);return ret;}
+	tag = (char*) malloc(sizeof(char)*129);
 	//long int pos=ftell(f);
 	//printf("position= %li\n",pos);
 	for (i=0;i<128;i++) {
 		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;
 	}
 	fclose(f);
 	//printf("tag readed: \n");
 	id=substring(tag,0,3);
 	//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.artist=subString(tag,33,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,"genre \"%s\"",ret.genre);
 	//if (DEBUG==1) putlog("id3v1 extracted");
+	free(tmp);
+	free(tag);
 	return ret;
 }