Message ID | 20211114172733.71602-5-sbabic@denx.de |
---|---|
State | Changes Requested |
Headers | show
Return-Path: <swupdate+bncBCXPLOXJ6IKRBHMOYWGAMGQE6X42KBA@googlegroups.com> X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=PZjlUupp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23d; helo=mail-lj1-x23d.google.com; envelope-from=swupdate+bncbcxploxj6ikrbhmoywgamgqe6x42kba@googlegroups.com; receiver=<UNKNOWN>) Received: from mail-lj1-x23d.google.com (mail-lj1-x23d.google.com [IPv6:2a00:1450:4864:20::23d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HsfRP1pvMz9t0k for <incoming@patchwork.ozlabs.org>; Mon, 15 Nov 2021 04:28:00 +1100 (AEDT) Received: by mail-lj1-x23d.google.com with SMTP id y23-20020a2e3217000000b00218c6ede162sf4411625ljy.23 for <incoming@patchwork.ozlabs.org>; Sun, 14 Nov 2021 09:28:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1636910877; cv=pass; d=google.com; s=arc-20160816; b=UWFRkP0VKj+sMryqbhS9jHR/aGIyOP5/0rMce7ceYlkJMkpn8iC73Ze4Y7IZ9qOsCv Al5pg+RpSlY9Jw9FxD+XRVwVMRnrLo6b10JfIv2yMib0XK7JMQbj6UXtOvBEB6D9TqEr j3HMqL/H+CbEg8PGupCaY1A+FqF+cCcRdEP2uIpInASpnns5Hk9WITsX5fBL5JyyVAXq MmWx/4UrRq6E3az4MZAj1/9kATFaTiMmiIpsQmxB4oASquuziWACystAb88cn8WzKynM KiThxf7qibZ/FHbeRkoX1MC5F8KvylphGUC1XSUfI97BlTgukvu0SH/QxIXBfAGktMyv +Drg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=NZDNybkCS6xuG/ra1ToX0UH4rCPtGEHaCWYUEDw+8gE=; b=PXl9Ce6BMmBZHPD10er+UGcdawA7LsqaYhdTje1E1grTp/ph4k25Yjf9yYUPUaf8M4 s7nm6IBw32AG+z0DiqxGljWY0+OTeanq6AJJYHmm6XrmS0ivtW2TaT4BcruoWKQc9Pbh YgJcuRh2vgi0sj2v31fgt5Auxtllu3305hsF9wRauxA5UzKwwPm3bJESL1fjFsjxAs5j jGIq2a9ZLr9DQxea4KEozclguvRCegfkh7RNbQ6da0OMJMJYCotMKhIwR011d7xHEwU4 7AZu9V2KiYDqxYcqaqDqWEYN+PKOf+j7rgpiTDNZbYfc/ZK+Dpj0Org/xCNDDh2scmgZ mBVQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=NZDNybkCS6xuG/ra1ToX0UH4rCPtGEHaCWYUEDw+8gE=; b=PZjlUupprEkBzlgmHZOCJ2dM7V1NE7G/gTfEaa2nsSRHKuaQRdxaefKd+5hhdGcoRL ZXtg7ezpD8ExwZ+Huhxa8DGf2Ob2/Nbl1Rr+eBhKQGPJexXuaZM6JLI03GOf475oh5aT cx5P2L2ohn3tmGcT0OA9QJACsTYWntWeOPnlWgECfboYhFdGK8I3mPWRwZ5wUO8CT5eE tzpEBU0Madnk5jQLDNee989Dr1DKdJ7PzloEhYc22ssvLy5vUsLWcHLvJ6uhXF+HJUio FDtu7XBWs05Eh972Ze7mtKerwvZG3QIyzP7I/a5DluatlCSOANcp1dojzJl8g7gJqjnX 6E6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=NZDNybkCS6xuG/ra1ToX0UH4rCPtGEHaCWYUEDw+8gE=; b=Rv2avTQVyqdDp0fLsvT5G1FjZHiL0xE2ioV+766XdlIvjffE5yg2R8C4OeyH4beUdF RjfZQ3ZFTabe7ZPg69xJPmvO0gtz/dv9lHGeSK2W/2OCx1FfENBR4dnHxCN4GVplGMCy IHLvkD84H8U153MKGssD8WXVTnLkLTk/fhZK+z2BiMPfk5kqF4Qlwcqar6+paB/vazbX +QVcG9ZoRnhtirkAQlRY2Hex17HhmuWIf/yH9VexKaBtROjO62qqDp+7CBSPuAUS3vZk 4ZbJuWvvzHcOA/W2rTqH6RlMcc2m58J8r3Ufwp771aSOTg6jV4e/LJCfuRGecSqI4yQY onYQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533DFvOfat6GE2z+NRt/4LNQv24EvgT/1ThCxPTrq6qQKcCv9vaJ ZvkyVSqb/OVv+sxO7kGIU/s= X-Google-Smtp-Source: ABdhPJzB4wj9jjwh+4Q0ktpZbsFxxv+NptrH4FIPY+2eRNIgvkGJ2zZC+xzZ0MLmz+noUk/zzWZ9+w== X-Received: by 2002:a05:6512:230e:: with SMTP id o14mr30424107lfu.490.1636910877441; Sun, 14 Nov 2021 09:27:57 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:898c:: with SMTP id c12ls1819086lji.11.gmail; Sun, 14 Nov 2021 09:27:56 -0800 (PST) X-Received: by 2002:a2e:3902:: with SMTP id g2mr32594824lja.321.1636910876586; Sun, 14 Nov 2021 09:27:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636910876; cv=none; d=google.com; s=arc-20160816; b=QbsrEo8ljFi7wcNpqtUH/qS6sUmBHjLKy4PuTpv066bs2Sg3QCMAH9gUbdUHLrA1FQ 7XVmXdXpaXiqdT/4P3ct8UEtdZ5awC/iHQWpuXc4Hg3qPBEWDKXEYqnqbe7HAm0sOaEx 9LQCjhsqCnaLJB7IyWyyUjJ84SfGCohkVNTB5oXrRMhBh4XXsGVQbn+tVuvOhvmkvWtb OBcB9pmtQNFsQBa1d3xko324GXt1j8/SlqgtIwivetaLy4NmukhTHeXXs9/yFChzuGvu 2yKEACf+Pt0FRwtDNXQID0eKOoFxnI+dZMMNg7b03YdmAECd8Yl4U2XFVG6BbpKbU2nE y/DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=HpaiGKAmCjXaxRUrYQp++iSsFUfrbJRzze6xnE126Pk=; b=nUyL3YWsOf/qPbREhnk09d8nayFq7ekoBl6IR+EEvjgrxBd8zRBHUA0NbsWw++siCR zD2BE8fzwa8l35u9e/bWrWatp8CwFepwKctbw8pCmVgh3oMFQYp6wX/MSGgvQHMqTlCj omb6SMr6KdmBgD2DUWlUhf+cjN9OyeNoL4PIigt5tUYDGlvEC+ur3qnwNOjwrW+bcz73 Ptk37B5b6G5V3Oj76jP4zTxw4nNMRrCu7zwqP17NUbdVtQ7CMpsbAW5ctccWNr8rvgcW encmDw6yqv00sLDhAETX3/YjWLi8iXYpS/UGRf6xnbKnVEr+XoNkU+SpPimGTJiVZ1pm EeCQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id f25si359740lfj.4.2021.11.14.09.27.56 for <swupdate@googlegroups.com> (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Nov 2021 09:27:56 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4HsfRJ09lwz1rk5m; Sun, 14 Nov 2021 18:27:56 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4HsfRJ0395z1qqkB; Sun, 14 Nov 2021 18:27:56 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id E1YjTLw66yNh; Sun, 14 Nov 2021 18:27:55 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Sun, 14 Nov 2021 18:27:55 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id C41074540853; Sun, 14 Nov 2021 18:27:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([IPv6:::1]) by localhost (mail.babic.homelinux.org [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Ox2yZHcN1dmm; Sun, 14 Nov 2021 18:27:51 +0100 (CET) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id 0B70F4541B6E; Sun, 14 Nov 2021 18:27:45 +0100 (CET) From: Stefano Babic <sbabic@denx.de> To: swupdate@googlegroups.com Cc: Stefano Babic <sbabic@denx.de> Subject: [swupdate] [PATCH V2 04/36] util: add safe version for realloc() Date: Sun, 14 Nov 2021 18:27:01 +0100 Message-Id: <20211114172733.71602-5-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211114172733.71602-1-sbabic@denx.de> References: <20211114172733.71602-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: <swupdate.googlegroups.com> X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: <https://groups.google.com/group/swupdate/post>, <mailto:swupdate@googlegroups.com> List-Help: <https://groups.google.com/support/>, <mailto:swupdate+help@googlegroups.com> List-Archive: <https://groups.google.com/group/swupdate List-Subscribe: <https://groups.google.com/group/swupdate/subscribe>, <mailto:swupdate+subscribe@googlegroups.com> List-Unsubscribe: <mailto:googlegroups-manage+605343134186+unsubscribe@googlegroups.com>, <https://groups.google.com/group/swupdate/subscribe> |
Series |
DELTA Update
|
expand
|
diff --git a/core/util.c b/core/util.c index da6bd10..f5d7c63 100644 --- a/core/util.c +++ b/core/util.c @@ -212,6 +212,18 @@ void freeargs (char **argv) } } +void *saferealloc(void *ptr, size_t size) { + void *ret = realloc(ptr, size); + /* + * Realloc does not touch the original block if fails. + * Policy is to free memory and returns with error (Null) + */ + if (!ret && ptr) + free(ptr); + return ret; +} + + /* * Concatente array of strings in a single string * The allocated string must be freed by the caller diff --git a/include/util.h b/include/util.h index 9c81e62..4f2995b 100644 --- a/include/util.h +++ b/include/util.h @@ -162,6 +162,7 @@ bool strtobool(const char *s); */ typedef int (*writeimage) (void *out, const void *buf, unsigned int len); +void *saferealloc(void *ptr, size_t size); int openfile(const char *filename); int copy_write(void *out, const void *buf, unsigned int len); #if defined(__FreeBSD__)
Realloc does not touch the passed pointer, creates a wrap-around function to be sure that the memory on the heap is always freed. Signed-off-by: Stefano Babic <sbabic@denx.de> --- core/util.c | 12 ++++++++++++ include/util.h | 1 + 2 files changed, 13 insertions(+)