From owner-svn-src-all@freebsd.org Sat Dec 10 23:53:21 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6EC3AC715FE for ; Sat, 10 Dec 2016 23:53:21 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-io0-x244.google.com (mail-io0-x244.google.com [IPv6:2607:f8b0:4001:c06::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3D6E6170B for ; Sat, 10 Dec 2016 23:53:21 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-io0-x244.google.com with SMTP id f73so14442167ioe.2 for ; Sat, 10 Dec 2016 15:53:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=Lb+VNcrmfY/lZh3tzmjyPJZC8zrqD4nYJZKKI74M0cY=; b=U/ht+C+o7LUPvhmmTgfnAYwQatf9MSvYO8Zs585beJkTki6fK6REqrlr5+NXi0xyB3 9XzOYqmnxAj+Wp1lfYTnc9gr9yaMagr9hDfZh75uIFuBTAawMbSBisTGn21KjBYZ8l1u DAaA+SLylHth6ty7x1unwxo2vGNfzKXIsocuQH+v5u8vNVwhbDi+L8JEZdUzZ8VEE0oZ IygkR4ewknVlNlOf1yj2osL7mZIcX8e8INFFYIJd4H1+VtaBX1w19alF3WouCudkmNx7 3344GbEn2phNMdS1jLrv9BS8FyhIyS/rGdz/Of5lDXM+QG63nK2mcp3tHSSW+RjsK1nM FNsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=Lb+VNcrmfY/lZh3tzmjyPJZC8zrqD4nYJZKKI74M0cY=; b=kR0OMTMSdm6sfoVK0tyv2JsXz4fkPwBHs2WEKCQDeS58EwxB2yJPdZS1/T1uz4fB9k cb5+G3E++ENigEuyspqdCJS6KtGwDbv0hCPAktKmhlWLli4WZpc2A+KU3juy1DaI94ve XLFXQtwe8avgX1KiJabsDjYm7A2SL+Vbf8h0Xjgq3mJChk5RGj0x0+QKEYDkCXxKZd5J V8Fwz7ewFC8TPz3qV4oHcJd7J2Ls+rxbvRBAFnHY/B5ytLJKiuIdpq/uhPqfi1LyA5ar UMOCKnzpeF1JGoSppHnnL7+YZIUsTvP/VJsqRM/gtMkhfaRuiKnKXK08szl3fiYTX8ob iicQ== X-Gm-Message-State: AKaTC02HLqs5DyFU8oF1VN/edcKF44xVx9pDZaJ38kbL2aL1tgXA2vBjbepCmDOhAMCPokHrR/Cub1gFef8vcQ== X-Received: by 10.36.122.135 with SMTP id a129mr4418559itc.103.1481414000541; Sat, 10 Dec 2016 15:53:20 -0800 (PST) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 10.79.31.199 with HTTP; Sat, 10 Dec 2016 15:53:20 -0800 (PST) X-Originating-IP: [69.53.245.200] In-Reply-To: <201612102326.uBANQZLE008552@repo.freebsd.org> References: <201612102326.uBANQZLE008552@repo.freebsd.org> From: Warner Losh Date: Sat, 10 Dec 2016 16:53:20 -0700 X-Google-Sender-Auth: IDiApwquLthBHJgsGDql72vZDW4 Message-ID: Subject: Re: svn commit: r309839 - head/sbin/camcontrol To: Ngie Cooper Cc: src-committers , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Dec 2016 23:53:21 -0000 Why not just unconditionally free them? You don't need to NULL them out. That would save a IMHO bogus macro. On Sat, Dec 10, 2016 at 4:26 PM, Ngie Cooper wrote: > Author: ngie > Date: Sat Dec 10 23:26:34 2016 > New Revision: 309839 > URL: https://svnweb.freebsd.org/changeset/base/309839 > > Log: > free/NULL out variables prior to calling strdup to avoid leaking memory > if arguments are specified more than once with "camcontrol timestamp". > > CID: 1366829, 1366831 > MFC after: 1 week > > Modified: > head/sbin/camcontrol/timestamp.c > > Modified: head/sbin/camcontrol/timestamp.c > ============================================================================== > --- head/sbin/camcontrol/timestamp.c Sat Dec 10 22:31:49 2016 (r309838) > +++ head/sbin/camcontrol/timestamp.c Sat Dec 10 23:26:34 2016 (r309839) > @@ -336,6 +336,11 @@ timestamp(struct cam_device *device, int > int single_arg = 0; > int do_utc = 0; > > +#define FREE(x) do { \ > + free(x); \ > + x = NULL; \ > +} while(0) > + > while ((c = getopt(argc, argv, combinedopt)) != -1) { > switch (c) { > case 'r': { > @@ -358,6 +363,7 @@ timestamp(struct cam_device *device, int > } > case 'f': { > single_arg++; > + FREE(format_string); > format_string = strdup(optarg); > if (format_string == NULL) { > warn("Error allocating memory for format " > @@ -369,6 +375,7 @@ timestamp(struct cam_device *device, int > } > case 'm': { > single_arg++; > + FREE(format_string); > format_string = strdup(MIL); > if (format_string == NULL) { > warn("Error allocating memory"); > @@ -382,6 +389,7 @@ timestamp(struct cam_device *device, int > break; > } > case 'T': > + FREE(timestamp_string); > timestamp_string = strdup(optarg); > if (timestamp_string == NULL) { > warn("Error allocating memory for format " > @@ -395,6 +403,8 @@ timestamp(struct cam_device *device, int > } > } > > +#undef FREE > + > if (action == -1) { > warnx("Must specify an action, either -r or -s"); > error = 1; >