harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r574352 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Date Mon, 10 Sep 2007 19:59:16 GMT
Author: hindessm
Date: Mon Sep 10 12:59:16 2007
New Revision: 574352

URL: http://svn.apache.org/viewvc?rev=574352&view=rev
Log:
Fixed some memory leaks.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=574352&r1=574351&r2=574352&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
Mon Sep 10 12:59:16 2007
@@ -295,15 +295,25 @@
 		remote_addr.sin_port = 0;
                 remote_addr.sin_addr.s_addr = 0;
 		address = malloc(sizeof(jbyte)*4);
+                if (NULL == address) {
+                  goto clean;
+                }
 		bzero(address,sizeof(jbyte)*4);
 	} else {
 		if(AF_INET != remote_addr.sin_family || length != sizeof(struct sockaddr))	{
 			return NULL;
 		}
 		address = malloc(sizeof(jbyte)*4);
+                if (NULL == address) {
+                  goto clean;
+                }
 		memcpy (address, &(remote_addr.sin_addr.s_addr), 4);
 	}
 	sock = malloc(sizeof(hysocket_struct));
+        /* TODO: where is sock free'd? */
+        if (NULL == sock) {
+          goto clean;
+        }
 	sock->sock = socket;
 	sock->family = AF_INET;
 
@@ -314,10 +324,12 @@
 		//socket
 		channel_class = (*env)->FindClass(env,"org/apache/harmony/nio/internal/SocketChannelImpl");
         	if(NULL == channel_class) {
+                    free(sock);
         	    goto clean;
 	        }
 		channel_object = getJavaNioChannelsSocketChannelImplObj(env,channel_class);
           	if(NULL == channel_object) {
+                    free(sock);
 	            goto clean;
         	}
 		// new and set FileDescript
@@ -340,6 +352,8 @@
 			(*env)->SetBooleanField(env,channel_object, bound_field,jtrue);
 		}
 	  } else {
+                // sock isn't used on this code path so we should free it
+                free(sock);
 		//serverSocket	
 		channel_class = (*env)->FindClass(env,"org/apache/harmony/nio/internal/ServerSocketChannelImpl");
         	if(NULL == channel_class) {
@@ -378,10 +392,12 @@
 	  // new DatagramChannel
 	  channel_class = (*env)->FindClass(env,"org/apache/harmony/nio/internal/DatagramChannelImpl");
           if(NULL == channel_class) {
+              free(sock);
               goto clean;
           }
           channel_object = getJavaNioChannelsSocketChannelImplObj(env,channel_class);
           if(NULL == channel_object) {
+              free(sock);
               goto clean;
           }
 	  // new and set FileDescript
@@ -395,10 +411,8 @@
 		(*env)->SetBooleanField(env,channel_object, bound_field,jtrue);			
 	  }
         }	
-clean:
+ clean:
 	free(address);
 	free(localAddr);
 	return channel_object;
 }
-
-



Mime
View raw message