From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DDFE5C77B7F for ; Mon, 8 May 2023 17:50:10 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 23A7985494; Mon, 8 May 2023 19:50:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="CFL0Rg0N"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D39AB8564F; Mon, 8 May 2023 19:50:06 +0200 (CEST) Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ECFC280B9E for ; Mon, 8 May 2023 19:50:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ralph.siemsen@linaro.org Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-3ef35d44612so53393521cf.1 for ; Mon, 08 May 2023 10:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683568202; x=1686160202; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HGZ4Aq1lo2FqDRuTMgxZyW5jgAiXOfWyIbLceUuJCCI=; b=CFL0Rg0Nrgwvk5jpdTUgS6vMpJnRaF+N7BXvwTA2DtjcXl+bB3ANdSXBDl/s/71paX Nx6BQgEcKFnblNH/bbwiInf1Ej0CRXvlNzS2a+8DeO/lfdRYv7hIVHjRGhH2yOkWUGW3 CfL/AGxcIwZ+zRTfVHiI8TTTMSaqhcL/8ClfzLJZCokkYfK3pkhT/qyP9HW0rv478ege e806R18xaNvJBMdhwI82IayezI6IfCcoIdk33lJoKva1AjmR6SmO9UuAxMVrSsH0j5yE R1QZGn16plmzPSmHG9T1GQnnbhHNrqCXam3N+RGsQlL/8STK9ut+Z23e+I/1sN15Jdyg aovA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683568202; x=1686160202; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HGZ4Aq1lo2FqDRuTMgxZyW5jgAiXOfWyIbLceUuJCCI=; b=WncqTfzRdUqm6ntEVA+lXogsIGMsibSkUXCaA7lpnDsX9WwpOPYsCxpbxshw27ocOM dUCuJMKbsGb5tJruFR83pE/kDM6hWCqoql5sXYqPNH4NVkRf4dv5nDZ+yOCM3q2TPKyu cCxmrTympu5aCwfmDf8Ng90LqgU2UFubBLjxe4bmRrcZmww3O1Da+8oq/2x8KrvkxwxE CJ6luTBj6e7K+BIq71v8/csk8Qis8tnCQS7BcveI3O6TlHo34qgkpgRJi/u5sWIX73lJ RByXdBftcT3VBTHvT5Blp4NRcoK0Onlpe8z63HtW8h9Tr8TDf1fC9pTLLz80epcId2hq Uhcg== X-Gm-Message-State: AC+VfDz5+4fuCpbIpijQCS0cDCZCXUeRyDAGy99DO0/XzN5eghCouFuA dmg3jplRymKaQEr5o7AQvsliEQ== X-Google-Smtp-Source: ACHHUZ5dYrfLQrHfGDuLYqxY+A8I4qESYWJaGFDpPtUwGTrMLfsJzuRmffTGT1oMdRhPuU7fiRmF4g== X-Received: by 2002:a05:622a:81:b0:3f3:7869:d2da with SMTP id o1-20020a05622a008100b003f37869d2damr19000728qtw.2.1683568202581; Mon, 08 May 2023 10:50:02 -0700 (PDT) Received: from localhost (rfs.netwinder.org. [206.248.184.2]) by smtp.gmail.com with ESMTPSA id x5-20020a05620a14a500b0074e4b1fe0aesm2709114qkj.94.2023.05.08.10.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 10:50:02 -0700 (PDT) Date: Mon, 8 May 2023 13:50:01 -0400 From: Ralph Siemsen To: Marek Vasut Cc: u-boot@lists.denx.de, Simon Glass , Heiko Thiery , Heinrich Schuchardt , Ilias Apalodimas , Marc Kleine-Budde , Massimo Pegorer , Mattijs Korpershoek , Max Krummenacher , Pali =?iso-8859-1?Q?Roh=E1r?= , Roman Kopytin , Safae Ouajih , Sean Anderson , Steven Lawrance , Sughosh Ganu , Weijie Gao Subject: Re: [PATCH v5 09/10] tools: spkgimage: add Renesas SPKG format Message-ID: <20230508175001.GA3380022@maple.netwinder.org> References: <20230424011515.1359255-1-ralph.siemsen@linaro.org> <20230424011515.1359255-10-ralph.siemsen@linaro.org> <97434886-26e1-d607-a7c1-7de6280f7d5a@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <97434886-26e1-d607-a7c1-7de6280f7d5a@mailbox.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On Sun, May 07, 2023 at 06:08:33PM +0200, Marek Vasut wrote: >[...] > >>+static int spkgimage_parse_config_file(char *filename) >>+{ >>+ FILE *fcfg; >>+ char line[256]; >>+ size_t line_num = 0; >>+ >>+ fcfg = fopen(filename, "r"); >>+ if (!fcfg) >>+ return -EINVAL; >>+ >>+ conf = calloc(1, sizeof(struct config_file)); >>+ if (!conf) >>+ return -ENOMEM; >>+ >>+ while (fgets(line, sizeof(line), fcfg)) { >>+ line_num += 1; >>+ >>+ /* Skip blank lines and comments */ >>+ if (line[0] == '\n' || line[0] == '#') >>+ continue; >>+ >>+ /* Strip any trailing newline */ >>+ line[strcspn(line, "\n")] = 0; >>+ >>+ /* Parse the line */ >>+ if (spkgimage_parse_config_line(line, line_num)) >>+ return -EINVAL; > >Wouldn't this return -EINVAL; leak memory allocated by the calloc() above? You are correct. But note that in the normal (non-error) code path, the structure remains allocated as well, and there is no good place to free() it, given the available callbacks in struct image_type_params. So I am relying on the OS to free all memory upon program exit, both in the error and non-error case. I would think this is reasonable for a small one-shot utility program, keeps things simple. If this is not acceptable, I can rework it, but there are quite a few other spots which would also need to free resources before bailing out. >[...] > >With that fixed: > >Reviewed-by: Marek Vasut I'll wait to hear back from you before applying this tag. Regards, Ralph