From f38261f666a2e41bbd189940ca7d419b3e726376 Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 11 Oct 2016 13:34:29 +0300 Subject: mpcinfo: Fix memory leaks Closes #1838 --- plugins/mpcinfo/mp3Info.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'plugins/mpcinfo/mp3Info.c') 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; } -- cgit 1.4.1