On 2014/11/29 02:02, Michal Nazarewicz <m...@google.com> wrote:
> +     static const char *filenames[] = {

Missing "const".

> +     char *pwd = NULL, *path, *str;
> +     unsigned i;
> +     FILE *fd;

Please declare variables where they are used.

> +     i = strlen(str);

As you see here, "i" has the wrong type.  This is hard to see with
your coding style.

> +             fd = fopen(path, "r");
> +             if (fd) {
> +                     pwd = mpd_parse_authinfo(host, port, fd);
> +             }
> +             fclose(fd);

Is fclose(NULL) legal?  I don't see this mentioned in the manpage, and
I assume it will crash.  (It does mention EBADF but I assume it's not
about a bad FILE* pointer but about a bad underlying file descriptor.)

Since you already have this NULL check, why not move it into the
block?

Oh, and in general, fopen() leaks file descriptors if another thread
decides to fork, because fopen() does not set the close-on-exec flag.
libmpdclient takes care to always set close-on-exec in a thread-safe
way (if the kernel supports it).
_______________________________________________
mpd-devel mailing list
mpd-devel@musicpd.org
http://mailman.blarg.de/listinfo/mpd-devel

Reply via email to