Author: kib
Date: Sat Apr 28 18:57:27 2012
New Revision: 234769
URL: http://svn.freebsd.org/changeset/base/234769

Log:
  Fix several memory and lock leaks on the out of memory condition.
  
  Reported by:  Matt Miller <matt matthewjmiller net>
  MFC after:    1 week

Modified:
  head/lib/libc/rpc/svc.c
  head/lib/libc/rpc/svc_raw.c

Modified: head/lib/libc/rpc/svc.c
==============================================================================
--- head/lib/libc/rpc/svc.c     Sat Apr 28 18:56:17 2012        (r234768)
+++ head/lib/libc/rpc/svc.c     Sat Apr 28 18:57:27 2012        (r234769)
@@ -108,8 +108,10 @@ xprt_register(xprt)
        if (__svc_xports == NULL) {
                __svc_xports = (SVCXPRT **)
                        mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
-               if (__svc_xports == NULL)
+               if (__svc_xports == NULL) {
+                       rwlock_unlock(&svc_fd_lock);
                        return;
+               }
                memset(__svc_xports, '\0', FD_SETSIZE * sizeof(SVCXPRT *));
        }
        if (sock < FD_SETSIZE) {
@@ -565,8 +567,14 @@ svc_xprt_alloc()
        SVCXPRT_EXT *ext;
 
        xprt = mem_alloc(sizeof(SVCXPRT));
+       if (xprt == NULL)
+               return (NULL);
        memset(xprt, 0, sizeof(SVCXPRT));
        ext = mem_alloc(sizeof(SVCXPRT_EXT));
+       if (ext == NULL) {
+               mem_free(xprt, sizeof(SVCXPRT));
+               return (NULL);
+       }
        memset(ext, 0, sizeof(SVCXPRT_EXT));
        xprt->xp_p3 = ext;
        ext->xp_auth.svc_ah_ops = &svc_auth_null_ops;

Modified: head/lib/libc/rpc/svc_raw.c
==============================================================================
--- head/lib/libc/rpc/svc_raw.c Sat Apr 28 18:56:17 2012        (r234768)
+++ head/lib/libc/rpc/svc_raw.c Sat Apr 28 18:57:27 2012        (r234769)
@@ -96,10 +96,22 @@ svc_raw_create()
                        mutex_unlock(&svcraw_lock);
                        return (NULL);
                }
-               if (__rpc_rawcombuf == NULL)
+               if (__rpc_rawcombuf == NULL) {
                        __rpc_rawcombuf = calloc(UDPMSGSIZE, sizeof (char));
+                       if (__rpc_rawcombuf == NULL) {
+                               free(srp);
+                               mutex_unlock(&svcraw_lock);
+                               return (NULL);
+                       }
+               }
                srp->raw_buf = __rpc_rawcombuf; /* Share it with the client */
                srp->server = svc_xprt_alloc();
+               if (srp->server == NULL) {
+                       free(__rpc_rawcombuf);
+                       free(srp);
+                       mutex_unlock(&svcraw_lock);
+                       return (NULL);
+               }
                svc_raw_private = srp;
        }
        srp->server->xp_fd = FD_SETSIZE;
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to