From: Hardening Date: Tue, 10 Feb 2015 09:26:32 +0000 (+0100) Subject: Handle OOM in Stream_New() X-Git-Tag: 2.0.0-beta1+android10~680^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=129c2084d7aa8d70784307817ace7d1f1bc6090e;p=platform%2Fupstream%2Ffreerdp.git Handle OOM in Stream_New() --- diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c index bce25f5..7ef0535 100644 --- a/winpr/libwinpr/utils/stream.c +++ b/winpr/libwinpr/utils/stream.c @@ -67,21 +67,28 @@ wStream* Stream_New(BYTE* buffer, size_t size) s = malloc(sizeof(wStream)); - if (s) - { - if (buffer) - s->buffer = buffer; - else - s->buffer = (BYTE*) malloc(size); + if (!s) + return NULL; - s->pointer = s->buffer; - s->capacity = size; - s->length = size; - s->pool = NULL; - s->count = 0; + if (buffer) + s->buffer = buffer; + else + s->buffer = (BYTE*) malloc(size); + + if (!s->buffer) + { + free(s); + return NULL; } + s->pointer = s->buffer; + s->capacity = size; + s->length = size; + + s->pool = NULL; + s->count = 0; + return s; }