From patchwork Thu Jun 24 16:48:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 1496705 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::43c; helo=mail-pf1-x43c.google.com; envelope-from=swupdate+bncbcl4hcw73qcbb3xo2kdamgqe3avkdaa@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=Edg55nKY; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=uVsXmous; dkim-atps=neutral Received: from mail-pf1-x43c.google.com (mail-pf1-x43c.google.com [IPv6:2607:f8b0:4864:20::43c]) (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 ozlabs.org (Postfix) with ESMTPS id 4G9mL968Kmz9sV8 for ; Fri, 25 Jun 2021 02:48:49 +1000 (AEST) Received: by mail-pf1-x43c.google.com with SMTP id t18-20020a056a001392b02903039eb2e663sf4379442pfg.5 for ; Thu, 24 Jun 2021 09:48:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1624553327; cv=pass; d=google.com; s=arc-20160816; b=SEEnn6fFcqfauwNrVD8wmaAKMnAESrAljlIUWYxFzLs63DjCVoPiJY3vj4eF8DV4Kw bcecsih3pflI3p46d8WnkG3Kx2X/1mrLEUt9sMh5XHVODS8BpnT85Wif9Cvcy37m3Zkd J0ZKT9nMq4ej0GgdWEV6017A9dNGt16kw2AE4XVZlt1An6J8nHQ4z3wQU50TLu+tmZpC dgI0y2NTXCcYxwyONxj8B0HJKw1D5Oeq534TiOnu/dbx8KRU9kRla22GjfbOYPOH4FME HTApNiNBlh0gO+xXkapT4RBM92WH0R/aZNpZkNVL2UiNcSZD/7LeTl/VV5Q+SCEinjFO pbqg== 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:message-id:date :subject:cc:to:from:sender:dkim-signature:dkim-signature; bh=esbiKezC1WhFaLIZv1FVOdxbavHasxUVnBdQ+rUqYBk=; b=I9X76NHujP2v9y9p463rKCmgP2635YCyNU24f6/IjtobyNJAjeiVbWVCdNuvSeacFj H1/AlQgabWYTqi9UttYLXJeAUDb/y+g2vdJzzxMY1rDL/QnU6k5SJylI+C5+y7lEoGWc XQ5XORtbHQsSP7Bm3RzW2ON1A8h2T7+yqd/CrK6MNDpGLcM/ZSQ38R/6xTQctLGe9DCT GzuwrkJZCsafOAkQtlQ2H41br4pP2hWsmzZFuh93ozR+7T9GT/U4vfNTApyO3W5NMVNH 8UVTX11K87yxM3cvdIYqkw2aN04xoib2KlnGTwrIK7FtkoiQZ24CfG2yRALwfW7hRlSm EH7Q== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e9YyqjlX; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::133 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id: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=esbiKezC1WhFaLIZv1FVOdxbavHasxUVnBdQ+rUqYBk=; b=Edg55nKYKs5pVDZ6uImGZNUe3ea6blqqageMnHCTIUdRjq92rcBbUwdjb3TBI1n6Tn J/vmou2lJ1c0rWCdBv8CnT+spJuX5shAyXSgUlrLZr8J4ogHlta0I5fwOqGgM5xLiUFA B1KRUDIioVUYg1+QAltA493x84g1EpzdsRoXlSbLQyqjT5RGsORL8QjFaOwy2DRijQdr 9C7SRIIwFp0fDZXNGxOrKK3l+ZWQ5X0WfxtAjctN+jMQhE+C69dk8FUw2e0p4mS//krV rVmfyC5wdvH/D+R+Sm7+tF3SJvx7q96nLQTiagdZvmHp4Kz6WJTdyh344OMUGMSwMik8 sUtA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id: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=esbiKezC1WhFaLIZv1FVOdxbavHasxUVnBdQ+rUqYBk=; b=uVsXmousQ8306wAj9bHfySq8Zb+irZQS4fUJ+Gpk4xDbQWV/s/c8sATowvxvx6SgDB DKbT33fOHWB+eUyOqeqz0n6FIwt+EMAdn0CI4yudHzSuZqfqneV1vjsMxmGW76hmtdpE hWj2Mnt9EwiVH+syYG5ceKFEswSHtcpcu6UjUgN2bvOneda6yKqvVv4AvFAKUYsXWgom my5EjslPdydZyZ0KTYgY+nbqhJbLTnWwICL3ylOwEX67Z7Ck1QKbWdlb7Epqa0KO9E3q KaO2Fdwn/wswm8VKO+7379t9NbwUxy6X57kv56A9Y5NfSg2pITQEwsdN7ut6HdhUolGk mBhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :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=esbiKezC1WhFaLIZv1FVOdxbavHasxUVnBdQ+rUqYBk=; b=kvi/A6MUi0kTX9100KS7wKog7mx+6CLl6UGIrrwXmueAvxe/GBWEO57PH3gWq75xrv yML/duqoGoFAEVQOtIxQrr9uUUiQpnmEyXDKHZIWVYYU4p/Ca2Jtz5EtNH0jqasyLPda clyq3C0hmiZpC9LWjqkZE5+ngpsIsuFuoaW8mhGXGyEVE5oTTlvxzX0RxlRB+kmza36M 2ADN6h2qtW8J3FBfOYJ4t3zzuLz6rXzCJO8AKnJYSaWvw8nK53gHF8BFRtXahB4tsl9j RtIAELI5OuzROwGnloHS8ZRTH0Y5B/LC/YkQDlhV0tY7XCI7D9fqIqf1PmL59r0wi4Ck zGQg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM532WGe26HOtnxJTGoh3kY+mV+fnVjDqp9gFQQpWd49ln3FkkztVH EyeKHFDQPpcFNh1JUHvIMN8= X-Google-Smtp-Source: ABdhPJxRCcCyTTsiPOskW7rVf7O3Z0U3+v22/F2guYb2T7IxVRI80fAOwAbHYfcuW/u1tYvBejJb2w== X-Received: by 2002:a63:903:: with SMTP id 3mr5453295pgj.147.1624553327046; Thu, 24 Jun 2021 09:48:47 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:90b:11d1:: with SMTP id gv17ls1086765pjb.1.canary-gmail; Thu, 24 Jun 2021 09:48:46 -0700 (PDT) X-Received: by 2002:a17:902:6a84:b029:127:9cd2:ec46 with SMTP id n4-20020a1709026a84b02901279cd2ec46mr2952827plk.35.1624553326319; Thu, 24 Jun 2021 09:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624553326; cv=none; d=google.com; s=arc-20160816; b=Y3wT5yyllK/8zqWNOKsxqA9vkOUAVkxAaNXtyg5w+p+nrFftqBFzcIOuBSR/NC83bf sLLEaZbbbxdQkFvvvqcWI+ocJyWtNQQvr6SJ5SmGiCETQuv+xIno4e5x/55gwRyAefan Ti7e1lNVjQoQOPMHcZ/FBhJ8jus6k4bUKCM7vgZ0CuX/9PddO36EakqpLpEWdFt0zr2j 0R4DS+ej5YCEx6eiyt7gAB/d4d6zcKePXYNxGUQxAWYC+3vRJN6b3YJx673drMB/41Qz 9NSwk09IZf7KG1WBjmGbxhvT0Qa212/hw2Qn1UiRgmXeZQL8SGl4WngQOAKd3XoiHEou YiRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=0kvKlfK9cITwXXdyKhWdttYnYYCYlNQJGfaz7HXxTp8=; b=RbuFK8xDpqaT4Fhi/0JwXi7bueVccfgLrIDH4BPzN+mNsmigQmFv3Sc/oISb3cV1ic 4O8hcZ6+FNy/lntYT4Alrrnb1mf68RYBJSm0P3uyG7APP5fnNDrOc8QaiWqjiJiIdeqd +HHSH/OoY5vL5ZnwrHwZqXJA1zx4aShblua5iZGKSzzlzmLeA25aRWqCd0oCCj+VbA2h EV6txW3xE4ZI4HIcAF6hjePE0NMNQvQCzEylc/f2ruwLr0guJJAUVjtd1w9OIdufC7tH U0FK0K1V7zdgZxpVgFPFXk0cxEaEfxzjeFDQP2uLrt10tCHvZOt2JO+2VqP+pYGK22pe nV8A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e9YyqjlX; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::133 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-il1-x133.google.com (mail-il1-x133.google.com. [2607:f8b0:4864:20::133]) by gmr-mx.google.com with ESMTPS id m1si265504pgq.5.2021.06.24.09.48.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 09:48:46 -0700 (PDT) Received-SPF: pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::133 as permitted sender) client-ip=2607:f8b0:4864:20::133; Received: by mail-il1-x133.google.com with SMTP id q9so7020920ilj.3 for ; Thu, 24 Jun 2021 09:48:46 -0700 (PDT) X-Received: by 2002:a92:6b06:: with SMTP id g6mr4357925ilc.270.1624553325556; Thu, 24 Jun 2021 09:48:45 -0700 (PDT) Received: from MacBook-Pro.localdomain ([143.131.13.3]) by smtp.gmail.com with ESMTPSA id n17sm2168416ilt.16.2021.06.24.09.48.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jun 2021 09:48:45 -0700 (PDT) From: James Hilliard To: swupdate@googlegroups.com Cc: James Hilliard Subject: [swupdate] [PATCH 1/1] diskpart: fix createtable memory leak Date: Thu, 24 Jun 2021 10:48:27 -0600 Message-Id: <20210624164827.32171-1-james.hilliard1@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Original-Sender: james.hilliard1@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e9YyqjlX; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::133 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Signed-off-by: James Hilliard Acked-by: Stefano Babic --- handlers/diskpart_handler.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c index acd21d4..dfdb55a 100644 --- a/handlers/diskpart_handler.c +++ b/handlers/diskpart_handler.c @@ -212,7 +212,7 @@ static int diskpart_assign_context(struct fdisk_context **cxt,struct img_type *i * This also lets us access the parent context. */ *cxt = fdisk_new_nested_context(parent, "dos"); - if (!cxt) { + if (!*cxt) { ERROR("Failed to allocate libfdisk nested context"); return -ENOMEM; } @@ -691,7 +691,7 @@ static int diskpart(struct img_type *img, unsigned long i; unsigned long hybrid = 0; struct hnd_priv priv = {FDISK_DISKLABEL_DOS}; - struct create_table *createtable = (struct create_table *)calloc(1, sizeof(struct create_table)); + struct create_table *createtable = NULL; if (!lbtype || (strcmp(lbtype, "gpt") && strcmp(lbtype, "dos"))) { ERROR("Just GPT or DOS partition table are supported"); @@ -807,6 +807,13 @@ static int diskpart(struct img_type *img, goto handler_release; } + createtable = calloc(1, sizeof(*createtable)); + if (!createtable) { + ERROR("OOM allocating createtable !"); + ret = -ENOMEM; + goto handler_release; + } + ret = diskpart_assign_context(&cxt, img, priv, hybrid, createtable); if (ret == -EACCES) goto handler_release; @@ -827,7 +834,8 @@ static int diskpart(struct img_type *img, oldtb = calloc(1, sizeof(*oldtb)); if (!oldtb) { ERROR("OOM loading partitions !"); - return -ENOMEM; + ret = -ENOMEM; + goto handler_exit; } /* @@ -912,6 +920,9 @@ handler_release: free(part); } + if (createtable) + free(createtable); + return ret; }