From 813060dd493114ab526c9d8988638611d55b9035 Mon Sep 17 00:00:00 2001 From: avos Date: Mon, 4 Mar 2019 03:30:39 +0000 Subject: [PATCH] MFC r344244: Fix memory / resource leaks in usr.sbin/rpc.ypupdated/update.c Re-apply r343909 to this file to get the issue fixed. PR: 204956 Reported by: David Binderman git-svn-id: svn://svn.freebsd.org/base/stable/10@344746 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.sbin/rpc.ypupdated/update.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/usr.sbin/rpc.ypupdated/update.c b/usr.sbin/rpc.ypupdated/update.c index 956b057ac..f3d54b833 100644 --- a/usr.sbin/rpc.ypupdated/update.c +++ b/usr.sbin/rpc.ypupdated/update.c @@ -263,11 +263,14 @@ localupdate(char *name, char *filename, u_int op, u_int keylen __unused, sprintf(tmpname, "%s.tmp", filename); rf = fopen(filename, "r"); if (rf == NULL) { - return (ERR_READ); + err = ERR_READ; + goto cleanup; } wf = fopen(tmpname, "w"); if (wf == NULL) { - return (ERR_WRITE); + fclose(rf); + err = ERR_WRITE; + goto cleanup; } err = -1; while (fgets(line, sizeof (line), rf)) { @@ -307,13 +310,17 @@ localupdate(char *name, char *filename, u_int op, u_int keylen __unused, fclose(rf); if (err == 0) { if (rename(tmpname, filename) < 0) { - return (ERR_DBASE); + err = ERR_DBASE; + goto cleanup; } } else { if (unlink(tmpname) < 0) { - return (ERR_DBASE); + err = ERR_DBASE; + goto cleanup; } } +cleanup: + free(tmpname); return (err); } -- 2.45.0