]> granicus.if.org Git - php/commitdiff
Fixed crash with pg_escape_*()
authorYasuo Ohgaki <yohgaki@php.net>
Thu, 4 Apr 2002 10:25:12 +0000 (10:25 +0000)
committerYasuo Ohgaki <yohgaki@php.net>
Thu, 4 Apr 2002 10:25:12 +0000 (10:25 +0000)
# I'll MFH later.

ext/pgsql/pgsql.c

index 1654f58d5a51989e5ed4d5c7762a7c65e7f6f7c0..934e0413b70a86ed2eb6c4e622fa4fcaeb1bf208 100644 (file)
@@ -2397,8 +2397,10 @@ PHP_FUNCTION(pg_escape_string)
                return;
        }
 
+       to = (char *)emalloc(len*2+1);
        len = (int)PQescapeString(to, from, strlen(from));
        if (len < 0) {
+               efree(to);
                RETURN_FALSE;
        }
        RETURN_STRINGL(to, len, 0);
@@ -2418,9 +2420,11 @@ PHP_FUNCTION(pg_escape_bytea)
 
        to = (char *)PQescapeBytea((unsigned char*)from, strlen(from), (size_t *)&len);
        if (len < 0) {
+               /* Don't need to free "to" here*/
                RETURN_FALSE;
        }
-       RETURN_STRINGL(to, len, 0);
+       RETURN_STRINGL(to, len, 1);
+       free(to);
 }
 /* }}} */
 #endif