]> arthur.barton.de Git - netatalk.git/commitdiff
fix a leak if malloc fail in of_alloc
authordidg <didg>
Thu, 21 Jul 2005 17:00:09 +0000 (17:00 +0000)
committerdidg <didg>
Thu, 21 Jul 2005 17:00:09 +0000 (17:00 +0000)
etc/afpd/ofork.c

index 7c227adaab68a177cc04da54d3709b0e519702ae..16d2743eea1f54b1f543c449e3a9d87ea89f54fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ofork.c,v 1.20.6.6.2.2 2005-02-10 01:23:15 didg Exp $
+ * $Id: ofork.c,v 1.20.6.6.2.3 2005-07-21 17:00:09 didg Exp $
  *
  * Copyright (c) 1996 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -210,11 +210,25 @@ struct stat     *st;
     }
     of = oforks[of_refnum];
 
+    /* here's the deal: we allocate enough for the standard mac file length.
+     * in the future, we'll reallocate in fairly large jumps in case
+     * of long unicode names */
+    of->of_namelen = 255 +1;
+    if (( of->of_name =(char *)malloc( of->of_namelen )) == NULL ) {
+        LOG(log_error, logtype_afpd, "of_alloc: malloc: %s", strerror(errno) );
+        free(of);
+        oforks[ of_refnum ] = NULL;
+        return NULL;
+    }
+
     /* see if we need to allocate space for the adouble struct */
     if (!ad) {
         ad = malloc( sizeof( struct adouble ) );
         if (!ad) {
             LOG(log_error, logtype_afpd, "of_alloc: malloc: %s", strerror(errno) );
+            free(of->of_name);
+            free(of);
+            oforks[ of_refnum ] = NULL;
             return NULL;
         }
 
@@ -228,7 +242,6 @@ struct stat     *st;
     }
 
     of->of_ad = ad;
-
     of->of_vol = vol;
     of->of_dir = dir;
 
@@ -242,18 +255,7 @@ struct stat     *st;
         d_ofork->of_d_prev = of;
     }
 
-    /* here's the deal: we allocate enough for the standard mac file length.
-     * in the future, we'll reallocate in fairly large jumps in case
-     * of long unicode names */
-    if (( of->of_name =(char *)malloc(255 + 1)) == NULL ) {
-        LOG(log_error, logtype_afpd, "of_alloc: malloc: %s", strerror(errno) );
-        if (!ad)
-            free(of->of_ad);
-        free(of);
-        oforks[ of_refnum ] = NULL;
-        return NULL;
-    }
-    strlcpy( of->of_name, path, of->of_namelen = 255 + 1);
+    strlcpy( of->of_name, path, of->of_namelen);
     *ofrefnum = refnum;
     of->of_refnum = refnum;
     of->key.dev = st->st_dev;