Author: omalley
Date: Fri Mar  4 03:52:00 2011
New Revision: 1077208

URL: http://svn.apache.org/viewvc?rev=1077208&view=rev
Log:
commit e39db0f464f4b1e1010b6893ef8ac8668b5afdcd
Author: Suresh Srinivas <[email protected]>
Date:   Tue Feb 23 13:33:42 2010 -0800

    HDFS-464 from 
https://issues.apache.org/jira/secure/attachment/12436681/hdfs-464.1.rel20.patch
    
    +++ b/YAHOO-CHANGES.txt
    +    HDFS-464. Fix memory leaks in libhdfs. (Christian Kunz via suresh)
    +

Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfs.c
    
hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfsJniHelper.c

Modified: 
hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfs.c
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/c%2B%2B/libhdfs/hdfs.c?rev=1077208&r1=1077207&r2=1077208&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfs.c 
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfs.c 
Fri Mar  4 03:52:00 2011
@@ -213,6 +213,7 @@ hdfsFS hdfsConnectAsUser(const char* hos
       if (groups == NULL || groups_size <= 0) {
         fprintf(stderr, "ERROR: groups must not be empty/null\n");
         errno = EINVAL;
+        destroyLocalReference(env, jConfiguration);
         return NULL;
       }
 
@@ -221,6 +222,8 @@ hdfsFS hdfsConnectAsUser(const char* hos
       if (jGroups == NULL) {
         errno = EINTERNAL;
         fprintf(stderr, "ERROR: could not construct groups array\n");
+        destroyLocalReference(env, jConfiguration);
+        destroyLocalReference(env, jUserString);
         return NULL;
       }
 
@@ -253,12 +256,14 @@ hdfsFS hdfsConnectAsUser(const char* hos
           destroyLocalReference(env, jGroups);
         }          
         destroyLocalReference(env, jUgi);
+        destroyLocalReference(env, jAttrString);
         return NULL;
       }
 
       destroyLocalReference(env, jUserString);
       destroyLocalReference(env, jGroups);
       destroyLocalReference(env, jUgi);
+      destroyLocalReference(env, jAttrString);
     }
 #else
     
@@ -539,12 +544,12 @@ hdfsFile hdfsOpenFile(hdfsFS fs, const c
     file = malloc(sizeof(struct hdfsFile_internal));
     if (!file) {
         errno = ENOMEM;
-        return NULL;
-    }
-    file->file = (*env)->NewGlobalRef(env, jVal.l);
-    file->type = (((flags & O_WRONLY) == 0) ? INPUT : OUTPUT);
+    } else {
+        file->file = (*env)->NewGlobalRef(env, jVal.l);
+        file->type = (((flags & O_WRONLY) == 0) ? INPUT : OUTPUT);
 
-    destroyLocalReference(env, jVal.l);
+        destroyLocalReference(env, jVal.l);
+    }
 
     done:
 
@@ -626,9 +631,11 @@ int hdfsExists(hdfsFS fs, const char *pa
                      jPath) != 0) {
         errno = errnoFromException(jExc, env, "org.apache.hadoop.fs."
                                    "FileSystem::exists");
+        destroyLocalReference(env, jPath);
         return -1;
     }
 
+    destroyLocalReference(env, jPath);
     return jVal.z ? 0 : -1;
 }
 
@@ -1144,6 +1151,7 @@ int hdfsDelete(hdfsFS fs, const char* pa
                      jPath) != 0) {
         errno = errnoFromException(jExc, env, "org.apache.hadoop.fs."
                                    "FileSystem::delete");
+        destroyLocalReference(env, jPath);
         return -1;
     }
 
@@ -1194,6 +1202,8 @@ int hdfsRename(hdfsFS fs, const char* ol
                      jOldPath, jNewPath) != 0) {
         errno = errnoFromException(jExc, env, "org.apache.hadoop.fs."
                                    "FileSystem::rename");
+        destroyLocalReference(env, jOldPath);
+        destroyLocalReference(env, jNewPath);
         return -1;
     }
 
@@ -1457,6 +1467,7 @@ int hdfsChmod(hdfsFS fs, const char* pat
     //Create an object of org.apache.hadoop.fs.Path
     jobject jPath = constructNewObjectOfPath(env, path);
     if (jPath == NULL) {
+      destroyLocalReference(env, jPermObj);
       return -3;
     }
 

Modified: 
hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfsJniHelper.c
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/c%2B%2B/libhdfs/hdfsJniHelper.c?rev=1077208&r1=1077207&r2=1077208&view=diff
==============================================================================
--- 
hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfsJniHelper.c
 (original)
+++ 
hadoop/common/branches/branch-0.20-security-patches/src/c++/libhdfs/hdfsJniHelper.c
 Fri Mar  4 03:52:00 2011
@@ -242,6 +242,7 @@ jarray constructNewArrayString(JNIEnv *e
       fprintf(stderr, "ERROR: jelem == NULL\n");
     }
     (*env)->SetObjectArrayElement(env, result, i, jelem);
+    (*env)->DeleteLocalRef(env, jelem);
   }
   return result;
 }


Reply via email to