From patchwork Mon May 28 18:27:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Holljes X-Patchwork-Id: 9127 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp2231286jad; Mon, 28 May 2018 11:28:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIwRp214IJHQ7ERP6kHcU1aCCQgtI6QpiTsvSSHjlpMkBkIBf1uye++XQyAnuT2qTfpFEqa X-Received: by 2002:a1c:9a89:: with SMTP id c131-v6mr10295893wme.146.1527532081719; Mon, 28 May 2018 11:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527532081; cv=none; d=google.com; s=arc-20160816; b=PXa75bh8vO921BB2LDLDHCgpAweP988ApvP7zKPxWd2v8svgvpEWzzbKgBDlWMc8K0 s1Mopw9XGpuAHfCiPvWU/gzPcEzIhfOy8SNep4LYm1m3uOwiXKIHsGmVDOVGbt4q3Y6i YUIrU1GBpbdBjAov7cjK2hPhzASLv+5OGEGDdbpOB22T7H2z6GqVamRAJEZ3etDGDSJq KjC5fowQN28o7fJ95z5FuL1yduujpyXMb8hi2Ym0ohTjLrIY/8ZpmHzByBMPzwCNt5Aa V16c4v3q39G8YnxLgFKxI3Hq/eG6fLckf8v59E5uK60VamsGYtDUsLUBIOrme0YBqAOv ua7A== 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=KtYbRB63AJUJSYqvlP/PO3qRdXMaKRK+f9qAp0XE4BAsMFCzFyjGesHy7LKONgHVA5 GamvBy1Z0ouS9kIV4K2y/MD8ZPx8dYH21d88L10WgJSpI522k6Xn5UzgnLjrUa+gNbeb U4hUN9ghjNcxy/T4MsSX36VVt42cv4nSECqQ8xtkdVR4YCqTlYItlv2ckIjqzlCnOaCt lYchXd+/fBu39wEyQkMth9fTCB4JZKepNZDlTDzOqfYff7KDNiSOzdOqBX1Q/O5XjC0G IpF15RvDau6Bsvgu21lojEJW54mCGni4o//rPDRAWw8h2mIZRHq2ekwUwu6hrcTFJgnc g6rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=WEU+qfZd; 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 d192-v6si171762wmd.100.2018.05.28.11.28.01; Mon, 28 May 2018 11:28:01 -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=WEU+qfZd; 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 A131A68A3DE; Mon, 28 May 2018 21:26:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8561768A37B for ; Mon, 28 May 2018 21:26:43 +0300 (EEST) Received: by mail-wm0-f54.google.com with SMTP id l1-v6so34255590wmb.2 for ; Mon, 28 May 2018 11:27:27 -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=WEU+qfZdQgAOu3pqRgvMclK6uP4PzrzO6F5OlVBA0mGDdTwBDFwCQTe+Xil7Txe7Ra /K+ynnAyVE/C36xdhMc3H/UVtI2y5yZ1pxHXnDcd0M8cnoLzIG46xSczmjkrIb2LUpFw ocRZF1Wf5b2S411SQjHpGW4YXCh3BbfAxVnBEg9qDXj7pUZjTw+9tOzQlXx3ZSyQDu6+ bEnwF0aJb9hVX7wFK3NBDK1/oJZpXw6h4Bvrzt0fOg5Zi6vhRzVK70xVzy56GiQ+od1b LeTsbKnJ0d1IYXPj7SjQFbHnPAe0QFUW9TC67oP5XKPaORnzmNj5DDLHGvNJjahmrHuI 9Pnw== 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=aGF80bQHwGOFHXH41H28zczHCRxRu6KdYbI+oPt89CXY5b1/PWvdF1/wuVMPSz8aP0 j1GZEmwBmPBeoMQIvzu3QNvE6XqaccURwQzdK7IVGM5DzoJd5K+pgBRHSUhbiKNl91fV IlKYEBfrcIpRRznQDlo3oG38ARRtKFHPJmxUU/iG6+ClsqudfEs8cG/opyyhTH4cFxH8 pH1h2d5LzUqy4/a+5n5y8nZhnCdH33OMMFHnh2tFYBOJTUFfL7CqwqzqL3vdfVM+sp7U XHI0a1uuH38FCa0R3baGfnqiaWAPdjnYt+IyiXnf7lvknEU0bsDBBvBadocHsSd0ecJE K7uA== X-Gm-Message-State: ALKqPwcr++inxCk/FYcI1rHCqTuOmA1z4QKeBM/50eH/2RGvrwAobnZ1 ix0dcdJFoJ4UX2Pk2rvIbzV2hg== X-Received: by 2002:a1c:3607:: with SMTP id d7-v6mr10508357wma.39.1527532046598; Mon, 28 May 2018 11:27:26 -0700 (PDT) Received: from localhost.localdomain ([46.5.2.0]) by smtp.gmail.com with ESMTPSA id g205-v6sm4126285wmg.43.2018.05.28.11.27.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 11:27:25 -0700 (PDT) From: Stephan Holljes To: ffmpeg-devel@ffmpeg.org Date: Mon, 28 May 2018 20:27:06 +0200 Message-Id: <20180528182711.3221-6-klaxa1337@googlemail.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180528182711.3221-1-klaxa1337@googlemail.com> References: <20180528182711.3221-1-klaxa1337@googlemail.com> Subject: [FFmpeg-devel] [PATCH 05/10] 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;