use new for buf, fix possible memlaek

This commit is contained in:
satbaby
2012-09-18 18:38:03 +02:00
parent ca748c6f48
commit a84ba36e0b
3 changed files with 34 additions and 22 deletions

View File

@@ -3948,7 +3948,7 @@ static off64_t cut_movie(MI_MOVIE_INFO * minfo, CMovieInfo * cmovie)
char spart[255];
char dpart[255];
char npart[255];
unsigned char * buf;
unsigned char psi[PSI_SIZE];
int r, i;
off64_t sdone, spos;
@@ -3965,9 +3965,9 @@ static off64_t cut_movie(MI_MOVIE_INFO * minfo, CMovieInfo * cmovie)
time_t tt1;
off64_t bpos, bskip;
buf = (unsigned char *) malloc(BUF_SIZE);
unsigned char * buf = new unsigned char[BUF_SIZE];
if(buf == 0) {
perror("malloc");
perror("new");
return 0;
}
@@ -4019,7 +4019,10 @@ printf("cut: end bookmark %d at %lld\n", bcount, books[bcount].pos);
bcount++;
}
printf("\n");
if(!bcount) return 0;
if(!bcount){
delete [] buf;
return 0;
}
qsort(books, bcount, sizeof(struct mybook), compare_book);
for(i = 0; i < bcount; i++) {
if(books[i].ok) {
@@ -4051,6 +4054,7 @@ printf("\n********* new file %s expected size %lld, start time %s", dpart, newsi
dstfd = open (dpart, O_CREAT|O_WRONLY|O_TRUNC| O_LARGEFILE, 0644);
if(dstfd < 0) {
perror(dpart);
delete [] buf;
return 0;
}
part = 0;
@@ -4179,7 +4183,7 @@ printf("********* total written %lld tooks %ld secs end time %s", spos, tt1-tt,
lseek64 (dstfd, 0, SEEK_SET);
ret_err:
close(dstfd);
free(buf);
delete [] buf;
if(was_cancel)
g_RCInput->postMsg(CRCInput::RC_home, 0);
return retval;
@@ -4195,7 +4199,6 @@ static off64_t copy_movie(MI_MOVIE_INFO * minfo, CMovieInfo * cmovie, bool onefi
char spart[255];
char dpart[255];
char npart[255];
unsigned char * buf;
unsigned char psi[PSI_SIZE];
int r, i;
off64_t sdone, spos = 0, btotal = 0;
@@ -4209,9 +4212,9 @@ static off64_t copy_movie(MI_MOVIE_INFO * minfo, CMovieInfo * cmovie, bool onefi
bool was_cancel = false;
int retval = 0;
buf = (unsigned char *) malloc(BUF_SIZE);
unsigned char * buf = new unsigned char[BUF_SIZE];
if(buf == 0) {
perror("malloc");
perror("new");
return 0;
}
@@ -4247,8 +4250,10 @@ printf("copy: jump bookmark %d at %lld len %lld\n", bcount, books[bcount].pos, b
bcount++;
}
}
if(!bcount) return 0;
if(!bcount){
delete [] buf;
return 0;
}
tt = time(0);
printf("********* %d boormarks, to %s file(s), expected size to copy %lld, start time %s", bcount, onefile ? "one" : "many", newsize, ctime (&tt));
snprintf(npart, sizeof(npart), "%s", name);
@@ -4389,7 +4394,7 @@ printf("copy: ********* %s: total written %lld took %ld secs\n", dpart, spos, tt
}
retval = 1;
ret_err:
free(buf);
delete [] buf;
if(was_cancel)
g_RCInput->postMsg(CRCInput::RC_home, 0);
return retval;