]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: check malloc return value
authorJoel Sing <jsing@google.com>
Mon, 26 Nov 2012 11:03:31 +0000 (22:03 +1100)
committerJoel Sing <jsing@google.com>
Mon, 26 Nov 2012 11:03:31 +0000 (22:03 +1100)
Check the return value from malloc - do not assume that we were
allocated memory just because we asked for it.

Update #4415.

R=minux.ma, daniel.morsing, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6782100

src/cmd/gc/lex.c
src/cmd/gc/sinit.c

index ad8bdebf036174404474310115ba1ac16b5d6289..8e16747efd5fda5ad74afd88d655c5fe0856a632 100644 (file)
@@ -1165,6 +1165,11 @@ l0:
        case '[':
                if(loophack || lstk != nil) {
                        h = malloc(sizeof *h);
+                       if(h == nil) {
+                               flusherrors();
+                               yyerror("out of memory");
+                               errorexit();
+                       }
                        h->v = loophack;
                        h->next = lstk;
                        lstk = h;
index d1438f1003008d3bbc8a4fac320677cc32a86781..e8010099d211e60cf1d034e4c50be172d4562306 100644 (file)
@@ -84,6 +84,11 @@ init1(Node *n, NodeList **out)
        }
        n->initorder = InitPending;
        l = malloc(sizeof *l);
+       if(l == nil) {
+               flusherrors();
+               yyerror("out of memory");
+               errorexit();
+       }
        l->next = initlist;
        l->n = n;
        l->end = nil;