]> granicus.if.org Git - php/commitdiff
Fixed memory leak on error in win32's opendir() emulation. (Patch by Wez)
authorIlia Alshanetsky <iliaa@php.net>
Wed, 9 Jun 2004 14:18:14 +0000 (14:18 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 9 Jun 2004 14:18:14 +0000 (14:18 +0000)
win32/readdir.c

index e33d19bde5be274629d90685518a4748c703e348..6aaafced442b8414e4ad6311bb468184128e735b 100644 (file)
@@ -37,14 +37,17 @@ DIR *opendir(const char *dir)
        dp = (DIR *) malloc(sizeof(DIR));
        dp->offset = 0;
        dp->finished = 0;
-       dp->dir = strdup(dir);
 
        if ((handle = _findfirst(filespec, &(dp->fileinfo))) < 0) {
-               if (errno == ENOENT)
+               if (errno == ENOENT) {
                        dp->finished = 1;
-               else
+               } else {
+                       free(dp);
+                       free(filespec);
                        return NULL;
+               }
        }
+       dp->dir = strdup(dir);
        dp->handle = handle;
        free(filespec);