From patchwork Thu May 31 22:23:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Holljes X-Patchwork-Id: 9196 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp161700jad; Thu, 31 May 2018 15:25:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIKiBJGRmqpVlqV7QrVElTnd/6m3+DFfafxXbxx9R5CadYjcuBKjKYmpuOxXVoNyqVUu5Om X-Received: by 2002:a5d:470b:: with SMTP id y11-v6mr347465wrq.107.1527805523127; Thu, 31 May 2018 15:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527805523; cv=none; d=google.com; s=arc-20160816; b=dn0psEYq106BskjtVixgl0i1x1QDdZ17PWUdDaO9OYVklW1TmuLRz5NpIYt8Pp486M J69UF2e26Nyso1wDI68D/QcC6YnXGoCCsvlYCmqrBwmO/b/c8HHNh3tgt6MIOB2DEHDH 00rWe3Fsv9N7xw4ttijxDKArwkwSu25Bmi/uYRoTYLbpH+MCHkmQd+EMy/qaEoWsCx59 Bt+a02FHyKf82A2DiI8gpUU8MsTg8+UYoh8US1JNBk7/EamrXPyT3cJqhIN9At0oEZor jhuwP66Pn/+60RyIzncYCA9GRQnGKRyRrqqASlK5KJvzQtOdbGQDZ6cmPRfZyD87X4ve KPow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=GhftkPZduy5jTiypoPA+ROifSFuYFA+zDUZxb5dO1/Q=; b=VemNNRwXXseH1xYRmYfkIZXkefmixEibNCxVkJMx5mamEDjfV9HJUzCWbZrRUb/ZHK IBXDeap0JgufvCGwKXoIuanDTEEYbR5hKII/EF5GiDt3ipXNqSIU4k8dju12nRIkoOkx UYJ4fSyWGA5o/y5BMmNWaO+tG2t2AFG+r+3I7kpxixM8hV6szTKKyrS5J78bZW8a9jbs 78uUb84O41W5qFIy/9jjg3mNU05mxx2LoW/ZEzpUsPAeQn5GIOT9Upu0sgCMyaecCeJO ygKwTagZ+7XPPHya7xQkvtpNtjqkHFRAzwBFXMikkM9vpY63bIGW2cmCklg3kDcWux5H rWdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=iAb9uL9M; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n67-v6si317068wmn.140.2018.05.31.15.25.22; Thu, 31 May 2018 15:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=iAb9uL9M; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC84F68A4AE; Fri, 1 Jun 2018 01:23:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f174.google.com (mail-wr0-f174.google.com [209.85.128.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DA7CD68A489 for ; Fri, 1 Jun 2018 01:23:46 +0300 (EEST) Received: by mail-wr0-f174.google.com with SMTP id k16-v6so7210712wro.0 for ; Thu, 31 May 2018 15:24:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bx8KVZG/aJp6g/+oFf3xQV5S5wpgebN29YtdOg1iPnQ=; b=iAb9uL9MVDbmZjgDxbI+gUoPLFTNe+0IE3FBq3okW8iNf5cmfjDTVg6vtmXJ4Mio3g Hh6JVTXwTwf2psApVvLqRtOh9YSt5+uNGX8PKyLSVR9i4gZ6NX6XRhyYY5KxQ9clFhcL uBBabHbVs4+hfBWbto0HzOmszdRHBvVr1vxfWMAWKr7z6Z7F8sl6IkkyMSx/LQO3x58H AgHjbfP5XvnIEb+bQH7Dk0D0Mj+v/zGMsLfkDnG5R+8yhW+Y02l9U6WeYkx/mfFxF89B E/o2rafvCj+32VwhltW/Ax3uTnE/Sr0WkQvLPRyN1FJpEQh3jNPy4DYi2ypV7STD3os5 S/Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bx8KVZG/aJp6g/+oFf3xQV5S5wpgebN29YtdOg1iPnQ=; b=PIocqmgY8mRg7/OrwFAMaQ3NqPFaq88SteMJ20E8/w1cKFYSGPPtBIA/EmgoOwi/jh TFMk5nQysC+fa8T76dxxtXb/S+FncLdTKi1K/irWrbJ9ClsJFFtGzSRVDiltf5mrnJh7 L27Ee40nk/Hka3Oze/w2rHx4aLCZq1JSVu1IKwE+5efZMuwhTecS9bSLpbGWNca6O6ys gaJI7hsU9tfGZTJ/Kz7MFR+i/CKqfQ68y8IkzQ1+f1WDOHi32cQoUJ/Dtmgao0u91uAx 35b+rXwo2S4xB6rHwnzsFd6gMRQWL0kkcP8HVC3Zg3le+ubNox/YxS8XukpoA8WfmPIY 1DIg== X-Gm-Message-State: ALKqPwfIrP1QiEuMnwfOYlgC7rCtYe3hbIDMh4auRZ7PTJwHCaPxS9eM F885oIg2n5nobjQRhDoWtgnptA== X-Received: by 2002:adf:878c:: with SMTP id b12-v6mr6966924wrb.92.1527805471300; Thu, 31 May 2018 15:24:31 -0700 (PDT) Received: from localhost.localdomain ([46.5.2.0]) by smtp.gmail.com with ESMTPSA id b72-v6sm705017wmf.11.2018.05.31.15.24.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 15:24:30 -0700 (PDT) From: Stephan Holljes To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Jun 2018 00:23:58 +0200 Message-Id: <20180531222415.24966-6-klaxa1337@googlemail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180531222415.24966-1-klaxa1337@googlemail.com> References: <20180528182711.3221-1-klaxa1337@googlemail.com> <20180531222415.24966-1-klaxa1337@googlemail.com> Subject: [FFmpeg-devel] [PATCH 05/22] publisher.c: Add allocation failure checks. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Stephan Holljes MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Stephan Holljes --- publisher.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/publisher.c b/publisher.c index 2e96f2f..9374c41 100644 --- a/publisher.c +++ b/publisher.c @@ -97,17 +97,37 @@ void publisher_init(struct PublisherContext **pub, char *stream_name) { int i; struct PublisherContext *pc = (struct PublisherContext*) av_malloc(sizeof(struct PublisherContext)); + if (!pc) { + av_log(NULL, AV_LOG_ERROR, "Could not allocate publisher context.\n"); + return; + } pc->nb_threads = 8; pc->stream_name = stream_name; pc->current_segment_id = -1; pc->shutdown = 0; pc->buffer = av_fifo_alloc_array(sizeof(struct Segment), MAX_SEGMENTS); + if (!pc->buffer) { + av_log(NULL, AV_LOG_ERROR, "Could not allocate publisher buffer.\n"); + av_free(pc); + return; + } pc->fs_buffer = av_fifo_alloc_array(sizeof(struct Segment), MAX_SEGMENTS); + if (!pc->fs_buffer) { + av_log(NULL, AV_LOG_ERROR, "Could not allocate publisher fast-start buffer.\n"); + av_fifo_free(pc->buffer); + av_free(pc); + return; + } pthread_mutex_init(&pc->buffer_lock, NULL); pthread_mutex_init(&pc->fs_buffer_lock, NULL); for (i = 0; i < MAX_CLIENTS; i++) { struct Client *c = &pc->clients[i]; c->buffer = av_fifo_alloc_array(sizeof(struct Segment), MAX_SEGMENTS); + if (!c->buffer) { + av_log(NULL, AV_LOG_ERROR, "Could not allocate client buffer.\n"); + publisher_free(pc); + return; + } c->ofmt_ctx = NULL; c->ffinfo = NULL; c->id = i;