iliaa           Thu Dec  5 18:19:03 2002 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4/ext/calendar  calendar.c 
  Log:
  Fixed memory leaks inside heb_number_to_chars().
  
  
Index: php4/ext/calendar/calendar.c
diff -u php4/ext/calendar/calendar.c:1.30 php4/ext/calendar/calendar.c:1.30.2.1
--- php4/ext/calendar/calendar.c:1.30   Thu Nov  7 09:52:02 2002
+++ php4/ext/calendar/calendar.c        Thu Dec  5 18:19:02 2002
@@ -18,7 +18,7 @@
    |          Wez Furlong               <[EMAIL PROTECTED]>            |
    +----------------------------------------------------------------------+
  */
-/* $Id: calendar.c,v 1.30 2002/11/07 14:52:02 wez Exp $ */
+/* $Id: calendar.c,v 1.30.2.1 2002/12/05 23:19:02 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -381,9 +381,9 @@
        for example both: year '5' and year '5000' product 'ä'.
        use the numeric one for calculations. 
  */
-static char* heb_number_to_chars(int n)
+static char* heb_number_to_chars(int n, char **ret)
 {
-       char *p, *old, *ret;
+       char *p, *old;
 
        p = emalloc(10);
        old = p;
@@ -392,8 +392,11 @@
           prevents the option breaking the jewish beliefs, and some other 
           critical resources ;)
           */
-       if (n > 9999 || n < 1)
+       if (n > 9999 || n < 1) {
+               efree(old);
+               *ret = NULL;
                return NULL;
+       }       
 
        /* alafim case */
        if (n / 1000) {
@@ -438,9 +441,10 @@
        }
 
        *p = '\0';
-       ret = emalloc((int) (p - old) + 1);
-       strncpy(ret, old, (int) (p - old) + 1);
-       return ret;
+       *ret = estrndup(old, (p - old) + 1);
+       p = *ret;
+       efree(old);
+       return p;
 }
 
 /* {{{ proto string jdtojewish(int juliandaycount)
@@ -450,6 +454,7 @@
        long julday, fl;
        int year, month, day;
        char date[10], hebdate[25];
+       char *dayp, *yearp;
        
        if (ZEND_NUM_ARGS() == 1) {
                if (zend_parse_parameters(1 TSRMLS_CC,"l", &julday) != SUCCESS) {
@@ -475,11 +480,14 @@
                        RETURN_FALSE;
                }
                
-               sprintf(hebdate, "%s %s %s", \
-                               heb_number_to_chars(day), \
-                               JewishMonthHebName[month], \
-                               heb_number_to_chars(year));
+               sprintf(hebdate, "%s %s %s", heb_number_to_chars(day, &dayp), 
+JewishMonthHebName[month], heb_number_to_chars(year, &yearp));
                
+               if (dayp) {
+                       efree(dayp);
+               }
+               if (yearp) {
+                       efree(yearp);   
+               }
                RETURN_STRING(hebdate, 1);
                
        }



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to