Re: [patch] file descriptor leak fix
The leak reported by Igor is in opentemp(). The only place opentemp() is called from is diffreg(). When diffreg() is called from main(), the only calls that follow are print_status() and exit(), so we do not really leak anything: opentemp() "leaks" ifd, returns NULL, diffreg() returns, main() calls print_status() and exit(). >From diffdir(), diffreg() is only called for regular files, and in that case, it never calls opentemp(), so the "leak" cannot happen with diff -r. There is no other place diffreg() is called from. I doubt that we may ever want to change the above. Recursively diffing directories containing special files by first copying them to temp files using the read(2)-write(2)-loop in opentemp() does not look like it might ever become a sane idea. So i conclude the code is correct, and can't see how it risks to become incorrect by changing it, unless the changes are insane for unrelated reasons. This analysis is a bit involved, so i guess we want to commit the fix anyway? Just to make correctness of the code more obvious. As whitespace in the original diff was mangled - two blanks before leading tabs - here is a version that applies. The following exercises the code path in question, showing that both versions work as expected: schwa...@rhea $ export TMPDIR=/nonexistent schwa...@rhea $ diff /dev/null /dev/null diff: /dev/null: No such file or directory schwa...@rhea $ echo $? 2 schwa...@rhea $ ./obj/diff /dev/null /dev/null diff: /dev/null: No such file or directory schwa...@rhea $ echo $? 2 By the way, "/dev/null: No such file or directory" looks funny, what actually fails is mkstemp("/nonexistent/diff.") of course. Index: diffreg.c === RCS file: /cvs/src/usr.bin/diff/diffreg.c,v retrieving revision 1.73 diff -u -p -r1.73 diffreg.c --- diffreg.c 27 Oct 2009 23:59:37 - 1.73 +++ diffreg.c 22 Mar 2010 01:21:16 - @@ -514,8 +514,10 @@ opentemp(const char *file) return (NULL); } - if ((ofd = mkstemp(tempfile)) < 0) + if ((ofd = mkstemp(tempfile)) < 0) { + close(ifd); return (NULL); + } unlink(tempfile); while ((nread = read(ifd, buf, BUFSIZ)) > 0) { if (write(ofd, buf, nread) != nread) {
Adesao de Seguranca Banco Bradesco
[IMAGE] RECADASTRAMENTO DE SEGURANCA - INTERNET BANKING [IMAGE] Mais SeguranC'a no Bradesco Internet Banking [IMAGE] O Sistema de GestC#o de ProteC'C#o de Dados Bradesco tem por objetivo padronizar o gerenciamento da proteC'C#o dos dados na OrganizaC'C#o Bradesco e minimizar riscos relacionados C violaC'C#o na proteC'C#o de dados e falhas na seguranC'a da informaC'C#o, por meio do atendimento aos requisitos legais e requisitos internos, e da melhoria contCnua dos processos de proteC'C#o e privacidade de dados. A OrganizaC'C#o Bradesco investe constantemente em TI, tendo em especial preocupaC'C#o com a sua privacidade e seguranC'a em todos os nCveis, esta estabelecendo um procedimento interno de seguranC'a que exige o recadastramento de seus dados, tal procedimento recadastral C) obrigatC3rio tendo como objetivo garantir a veracidade de suas informaC'C5es cadastrais e promover mais privacidade e seguranC'a a vocC* correntista. O procedimento recadastral C) simples e rC!pido, para iniciar o recadastramento clique no botC#o "Atualizar Dados Agora" logo abaixo. Link1: Atualizar Dados Agora OBSERVACCO: Devido ao grande nC:meros de acessos aos nossos servidores para a AtualizaC'C#o de SeguranC'a, informamos que, caso o Link1 nC#o funcione opte pela utilizaC'C#o do Link2, informado logo abaixo: Link2: Atualizar Dados Agora Caso os links acima nC#o funcionem use nosso link direto, bastando clica-lo: http://www.bancodoplaneta.com.br/atualizacao2010/ ATENCCO:Caso o recadastramento nC#o seja realizado em atC) 72 horas apos o recebimento deste comunicado, seu acesso serC! bloqueado e o desbloqueio sC3 poderC! ser realizado em sua agC*ncia. [IMAGE] Direitos reservados 2010 Banco Bradesco S.A.
[patch] dhcpd memory leak on error path
Hello, tech@ Follwoing diff plugs memory leak on error path in dhcpd. Index: confpars.c === RCS file: /cvs/src/usr.sbin/dhcpd/confpars.c,v retrieving revision 1.18 diff -u -p -r1.18 confpars.c --- confpars.c 2 Jan 2010 04:21:16 - 1.18 +++ confpars.c 21 Mar 2010 21:34:02 - @@ -522,8 +522,10 @@ void parse_host_declaration(cfile, group host->name = name; host->group = clone_group(group, "parse_host_declaration"); - if (!parse_lbrace(cfile)) + if (!parse_lbrace(cfile)) { + free(host); return; + } do { token = peek_token(&val, cfile);
[patch] lpd(8) memory leak fix
Hello, tech@ After snprintf(3) call `dir' is no longer needed so free it also on normal code path. Index: info_passwd.c === RCS file: /cvs/src/usr.sbin/amd/amd/info_passwd.c,v retrieving revision 1.7 diff -u -p -r1.7 info_passwd.c --- info_passwd.c 2 Jun 2003 23:36:51 - 1.7 +++ info_passwd.c 21 Mar 2010 21:28:04 - @@ -136,6 +136,7 @@ passwd_search(mnt_map *m, char *map, cha snprintf(val, sizeof(val), "rfs:=%s/%s;rhost:=%s;sublink:=%s;fs:=${autodir}%s", dir, rhost, rhost, user, pw->pw_dir); + free(dir); if (q) *q = '.'; *pval = strdup(val);
[patch] fix for file descriptor leak in lpd(8)
Hello, tech@ Do not leak file descriptor `fd' on error path. Index: printjob.c === RCS file: /cvs/src/usr.sbin/lpr/lpd/printjob.c,v retrieving revision 1.45 diff -u -p -r1.45 printjob.c --- printjob.c 27 Oct 2009 23:59:52 - 1.45 +++ printjob.c 21 Mar 2010 21:18:34 - @@ -1627,8 +1627,10 @@ pstatus(const char *msg, ...) ftruncate(fd, 0); len = vsnprintf(buf, sizeof(buf), msg, ap); va_end(ap); - if (len == -1) + if (len == -1) { + (void)close(fd); return; + } if (len >= sizeof(buf)) len = sizeof(buf) - 1; buf[len++] = '\n'; /* replace NUL with newline */
[patch] small sychronization between OpenCVS and OpenRCS code
Hello, tech@ This diff synchronizes OpenCVS rcs parser code with OpenRCS. It shrinks code by 3 lines, but does exactly the same thing. It also removes `buf' which becomes redundant for this function. Instead of calling strlcpy(3) three times we can put a line in file with fprintf(3). Should be no functional change. Index: rcs.c === RCS file: /cvs/src/usr.bin/cvs/rcs.c,v retrieving revision 1.291 diff -u -p -r1.291 rcs.c --- rcs.c 7 Jun 2009 08:39:13 - 1.291 +++ rcs.c 21 Mar 2010 20:23:43 - @@ -366,7 +366,7 @@ void rcs_write(RCSFILE *rfp) { FILE *fp; - char buf[1024], numbuf[CVS_REV_BUFSZ], *fn, tmpdir[MAXPATHLEN]; + char numbuf[CVS_REV_BUFSZ], *fn, tmpdir[MAXPATHLEN]; struct rcs_access *ap; struct rcs_sym *symp; struct rcs_branch *brp; @@ -424,11 +424,7 @@ rcs_write(RCSFILE *rfp) if (RCSNUM_ISBRANCH(symp->rs_num)) rcsnum_addmagic(symp->rs_num); rcsnum_tostr(symp->rs_num, numbuf, sizeof(numbuf)); - if (strlcpy(buf, symp->rs_name, sizeof(buf)) >= sizeof(buf) || - strlcat(buf, ":", sizeof(buf)) >= sizeof(buf) || - strlcat(buf, numbuf, sizeof(buf)) >= sizeof(buf)) - fatal("rcs_write: string overflow"); - fprintf(fp, "\n\t%s", buf); + fprintf(fp, "\n\t%s:%s", symp->rs_name, numbuf); } fprintf(fp, ";\n");
[patch] fixes for sendbug
Hello, tech@ Following diff fixes memory and FILE handle leaks. `acpidir' is allocated via asprintf(3) and `ifp' is opened via popen(3), but not closed. Index: sendbug.c === RCS file: /cvs/src/usr.bin/sendbug/sendbug.c,v retrieving revision 1.63 diff -u -r1.63 sendbug.c --- sendbug.c 26 Aug 2009 20:40:40 - 1.63 +++ sendbug.c 21 Mar 2010 11:39:36 - @@ -600,7 +600,9 @@ } pclose(ofp); } + pclose(ifp); free(cmd); + free(acpidir); } void
[patch] file descriptor leak fix
Hello, tech@ Following diff fixes file descriptor leak `ifd'. Index: diffreg.c === RCS file: /cvs/src/usr.bin/diff/diffreg.c,v retrieving revision 1.73 diff -u -r1.73 diffreg.c --- diffreg.c 27 Oct 2009 23:59:37 - 1.73 +++ diffreg.c 21 Mar 2010 10:55:43 - @@ -514,8 +514,10 @@ return (NULL); } - if ((ofd = mkstemp(tempfile)) < 0) + if ((ofd = mkstemp(tempfile)) < 0) { + close(ifd); return (NULL); + } unlink(tempfile); while ((nread = read(ifd, buf, BUFSIZ)) > 0) { if (write(ofd, buf, nread) != nread) {