r2599: avoid free()ing our static unalloceted memory that ends up in memory corruption.
authorSimo Sorce <idra@samba.org>
Fri, 24 Sep 2004 17:38:23 +0000 (17:38 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:47 +0000 (10:52 -0500)
source/lib/xfile.c

index 1534dd855e9e2b72202231e5382a1bcd03f3b1fe..da5ec126c1f9b94db09549eebe72e59b294424f2 100644 (file)
@@ -135,7 +135,12 @@ int x_fclose(XFILE *f)
                memset(f->buf, 0, f->bufsize);
                SAFE_FREE(f->buf);
        }
-       SAFE_FREE(f);
+       /* check the file descriptor given to the function is NOT one of the static
+        * descriptor of this libreary or we will free unallocated memory
+        * --sss */
+       if (f != x_stdin && f != x_stdout && f != x_stderr) {
+               SAFE_FREE(f);
+       }
        return ret;
 }