]> arthur.barton.de Git - netatalk.git/commitdiff
Only read rfork if its there
authorFrank Lahm <franklahm@googlemail.com>
Mon, 20 Dec 2010 11:55:41 +0000 (12:55 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 20 Dec 2010 11:55:41 +0000 (12:55 +0100)
libatalk/adouble/ad_open.c

index 660caea1781848fa6c9d64742d0a70ff065e8ed4..37d42fe1e1753bffc189d8fc05a4953639a06043 100644 (file)
@@ -731,24 +731,34 @@ static int ad_open_rf(const char *path, int adflags, int oflags, int mode, struc
         default:
             LOG(log_warning, logtype_default, "ad_open_rf(\"%s\"): %s",
                 abspath(path), strerror(errno));
-            return -1;
+            ret = -1;
+            goto exit;
         }
     }
 
     /* Round up and allocate buffer */
     size_t roundup = ((ad->ad_rlen / RFORK_EA_ALLOCSIZE) + 1) * RFORK_EA_ALLOCSIZE;
-    if ((ad->ad_resforkbuf = malloc(roundup)) == NULL)
-        return -1;
+    if ((ad->ad_resforkbuf = malloc(roundup)) == NULL) {
+        ret = -1;
+        goto exit;
+    }
 
     ad->ad_resforkbufsize = roundup;
 
     /* Read the EA into the buffer */
-    if (sys_lgetxattr(cfrombstr(ad->ad_fullpath), AD_EA_RESO, ad->ad_resforkbuf, ad->ad_rlen) == -1)
-        return -1;
+    if (ad->ad_rlen > 0) {
+        if (sys_lgetxattr(cfrombstr(ad->ad_fullpath), AD_EA_RESO, ad->ad_resforkbuf, ad->ad_rlen) == -1) {
+            ret = -1;
+            goto exit;
+        }       
+    }
 
+exit:
     if (ret != 0) {
         free(ad->ad_resforkbuf);
         ad->ad_resforkbuf = NULL;
+        ad->ad_rlen = 0;
+        ad->ad_resforkbufsize = 0;
     }
 
     return ret;