{"id":807095,"url":"http://patchwork.ozlabs.org/api/1.2/patches/807095/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/20170829134515.9345-1-christian.brauner@ubuntu.com/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/1.2/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170829134515.9345-1-christian.brauner@ubuntu.com>","list_archive_url":null,"date":"2017-08-29T13:45:14","name":"[1/2,v4] openpty: close slave pty fd on error","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"255f69b0f1b80d7cf0eab865ac6fcc7cc4ebc555","submitter":{"id":72235,"url":"http://patchwork.ozlabs.org/api/1.2/people/72235/?format=json","name":"Christian Brauner","email":"christian.brauner@ubuntu.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/20170829134515.9345-1-christian.brauner@ubuntu.com/mbox/","series":[{"id":373,"url":"http://patchwork.ozlabs.org/api/1.2/series/373/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=373","date":"2017-08-29T13:45:14","name":"[1/2,v4] openpty: close slave pty fd on error","version":4,"mbox":"http://patchwork.ozlabs.org/series/373/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/807095/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/807095/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-return-83816-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-83816-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"aaUNtSNc\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xhVKG4zKnz9sRV\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 29 Aug 2017 23:46:10 +1000 (AEST)","(qmail 129014 invoked by alias); 29 Aug 2017 13:46:00 -0000","(qmail 125277 invoked by uid 89); 29 Aug 2017 13:45:42 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; q=dns; s=default; b=h18W5wQy6uSqgHvN5UGq6b6KiWomKkE\n\txHGnAzHb52JOVLM0joRqBLyl9Zo1IRag1k81jGUTLomuWhRbN+qmq6MnrK3C8AMq\n\t5epxwaF+bTMRTfpYJ8BFsplzgt0+aI+m3yVnP/njKC6IKL7eJpBQgn0SbXBZxYN4\n\tIIcQGjTJ/l88=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:from:to:cc:subject:date:message-id:in-reply-to\n\t:references; s=default; bh=GH0+n6AfWN6pB3zDgXiuFdRCkUs=; b=aaUNt\n\tSNcdzO0FLmZuuiCIv2dfXluz0JAR7BHiMaUJq82YbIROJ3jvUm0uP2BKDbj1UGrM\n\td96gpeyZ0aQCOKbxYX52KusSBMEM5ecDBGn9nnNJ9rlWHOr20dIdLsJuinBukBiH\n\tgnffAofZuWzJCZoG75a+peoBsPXo4cKM1h9T8g=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=xxx","X-HELO":"mx1.mailbox.org","From":"Christian Brauner <christian.brauner@ubuntu.com>","To":"libc-alpha@sourceware.org, stgraber@stgraber.org, serge@hallyn.com,\n\tfweimer@redhat.com, joseph@codesourcery.com","Cc":"Christian Brauner <christian.brauner@ubuntu.com>","Subject":"[PATCH 1/2 v4] openpty: close slave pty fd on error","Date":"Tue, 29 Aug 2017 15:45:14 +0200","Message-Id":"<20170829134515.9345-1-christian.brauner@ubuntu.com>","In-Reply-To":"<a05d5603-c074-966d-f75e-cb268d0dc249@redhat.com>","References":"<a05d5603-c074-966d-f75e-cb268d0dc249@redhat.com>"},"content":"When openpty() failed only the master fd was closed so far. Let's close the\nslave fd as well. Also, let's unify the error handling.\n\nSigned-off-by: Christian Brauner <christian.brauner@ubuntu.com>\n---\nChangelog 2017-08-29:\n* Unify error handling: use a common function exit that frees everything that\n  needs freeing. (@Florian)\n---\n ChangeLog       |  4 ++++\n login/openpty.c | 28 ++++++++++++++--------------\n 2 files changed, 18 insertions(+), 14 deletions(-)","diff":"diff --git a/ChangeLog b/ChangeLog\nindex bc1cf94dc3..bc5fb8e27f 100644\n--- a/ChangeLog\n+++ b/ChangeLog\n@@ -1,3 +1,7 @@\n+2017-08-26  Christian Brauner  <christian.brauner@ubuntu.com>\n+\n+\t* login/openpty.c (openpty): Close slave pty fd and unify error handling.\n+\n 2017-08-25  H.J. Lu  <hongjiu.lu@intel.com>\n \n \t* sysdeps/x86/cpu-features.h [__ASSEMBLER__]\ndiff --git a/login/openpty.c b/login/openpty.c\nindex 41ab0483e2..a7b1ab5dde 100644\n--- a/login/openpty.c\n+++ b/login/openpty.c\n@@ -92,29 +92,24 @@ openpty (int *amaster, int *aslave, char *name,\n   char _buf[512];\n #endif\n   char *buf = _buf;\n-  int master, slave;\n+  int master, ret = -1, slave = -1;\n \n   master = getpt ();\n   if (master == -1)\n     return -1;\n \n   if (grantpt (master))\n-    goto fail;\n+    goto on_error;\n \n   if (unlockpt (master))\n-    goto fail;\n+    goto on_error;\n \n   if (pts_name (master, &buf, sizeof (_buf)))\n-    goto fail;\n+    goto on_error;\n \n   slave = open (buf, O_RDWR | O_NOCTTY);\n   if (slave == -1)\n-    {\n-      if (buf != _buf)\n-\tfree (buf);\n-\n-      goto fail;\n-    }\n+    goto on_error;\n \n   /* XXX Should we ignore errors here?  */\n   if (termp)\n@@ -129,12 +124,17 @@ openpty (int *amaster, int *aslave, char *name,\n   if (name != NULL)\n     strcpy (name, buf);\n \n+  ret = 0;\n+\n+ on_error:\n+  close (master);\n+\n+  if (slave != -1)\n+    close(slave);\n+\n   if (buf != _buf)\n     free (buf);\n-  return 0;\n \n- fail:\n-  close (master);\n-  return -1;\n+  return ret;\n }\n libutil_hidden_def (openpty)\n","prefixes":["1/2","v4"]}