Re: Patch a potential memory leak in describeOneTableDetails() - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject Re: Patch a potential memory leak in describeOneTableDetails()
Date
Msg-id 20220222.151401.1451845726756615483.horikyota.ntt@gmail.com
Whole thread Raw
In response to Re: Patch a potential memory leak in describeOneTableDetails()  (Daniel Gustafsson <daniel@yesql.se>)
Responses Re: Patch a potential memory leak in describeOneTableDetails()
Re: Patch a potential memory leak in describeOneTableDetails()
List pgsql-hackers
At Mon, 21 Feb 2022 10:24:23 +0100, Daniel Gustafsson <daniel@yesql.se> wrote in 
> I think it's because you've indented your new code differently from the
> existing, such that the if (res) clause is indented equally to the previous
> pg_free(tableinfo.relam) call, making it look like they are in the same block:

Yeah, I (wrongly) thought that they have the same indentation.

> > +    if (tableinfo.relam)
> > +        pg_free(tableinfo.relam);
> > 
> >     if (res)
> >         PQclear(res);

But actually the lines I added are space-indented but the following
existing line is tab-indented.

Anyway, don't we use the -ftabstop option flag to silence compiler?
The warning is contradicting our convention. The attached adds that
flag.


By the way, the doc says that:

https://www.postgresql.org/docs/14/source-format.html

> The text browsing tools more and less can be invoked as:
>    more -x4
>    less -x4
> to make them show tabs appropriately.

But AFAICS the "more" command on CentOS doesn't have -x options nor
any option to change tab width and I don't find a document that
suggests its existence on other platforms.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
From 4e3b0c2ce6a2dd60d11100deb2db80ff07455d0d Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Tue, 22 Feb 2022 14:41:10 +0900
Subject: [PATCH] Fit compiler tabstop to our convension

Set -ftabstop to 4 so that -Wmisleading-indentation doesn't makes
false warnings.
---
 configure    | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac |  3 ++
 2 files changed, 95 insertions(+)

diff --git a/configure b/configure
index f3cb5c2b51..887ed733eb 100755
--- a/configure
+++ b/configure
@@ -6219,6 +6219,98 @@ if test x"$pgac_cv_prog_CXX_cxxflags__fexcess_precision_standard" = x"yes"; then
 fi
 
 
+  # Fit tab width for -Wmisleading-indentation to our convention
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -ftabstop=4, for CFLAGS" >&5
+$as_echo_n "checking whether ${CC} supports -ftabstop=4, for CFLAGS... " >&6; }
+if ${pgac_cv_prog_CC_cflags__ftabstop_4+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CFLAGS=$CFLAGS
+pgac_save_CC=$CC
+CC=${CC}
+CFLAGS="${CFLAGS} -ftabstop=4"
+ac_save_c_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag=yes
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  pgac_cv_prog_CC_cflags__ftabstop_4=yes
+else
+  pgac_cv_prog_CC_cflags__ftabstop_4=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_c_werror_flag
+CFLAGS="$pgac_save_CFLAGS"
+CC="$pgac_save_CC"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__ftabstop_4" >&5
+$as_echo "$pgac_cv_prog_CC_cflags__ftabstop_4" >&6; }
+if test x"$pgac_cv_prog_CC_cflags__ftabstop_4" = x"yes"; then
+  CFLAGS="${CFLAGS} -ftabstop=4"
+fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -ftabstop=4, for CXXFLAGS" >&5
+$as_echo_n "checking whether ${CXX} supports -ftabstop=4, for CXXFLAGS... " >&6; }
+if ${pgac_cv_prog_CXX_cxxflags__ftabstop_4+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CXXFLAGS=$CXXFLAGS
+pgac_save_CXX=$CXX
+CXX=${CXX}
+CXXFLAGS="${CXXFLAGS} -ftabstop=4"
+ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+ac_cxx_werror_flag=yes
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  pgac_cv_prog_CXX_cxxflags__ftabstop_4=yes
+else
+  pgac_cv_prog_CXX_cxxflags__ftabstop_4=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+CXXFLAGS="$pgac_save_CXXFLAGS"
+CXX="$pgac_save_CXX"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__ftabstop_4" >&5
+$as_echo "$pgac_cv_prog_CXX_cxxflags__ftabstop_4" >&6; }
+if test x"$pgac_cv_prog_CXX_cxxflags__ftabstop_4" = x"yes"; then
+  CXXFLAGS="${CXXFLAGS} -ftabstop=4"
+fi
+
+
   # Optimization flags for specific files that benefit from loop unrolling
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -funroll-loops, for CFLAGS_UNROLL_LOOPS"
>&5
 $as_echo_n "checking whether ${CC} supports -funroll-loops, for CFLAGS_UNROLL_LOOPS... " >&6; }
diff --git a/configure.ac b/configure.ac
index 19d1a80367..808d3d268d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -518,6 +518,9 @@ if test "$GCC" = yes -a "$ICC" = no; then
   # Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
   PGAC_PROG_CC_CFLAGS_OPT([-fexcess-precision=standard])
   PGAC_PROG_CXX_CFLAGS_OPT([-fexcess-precision=standard])
+  # Fit tab width for -Wmisleading-indentation to our convention
+  PGAC_PROG_CC_CFLAGS_OPT([-ftabstop=4])
+  PGAC_PROG_CXX_CFLAGS_OPT([-ftabstop=4])
   # Optimization flags for specific files that benefit from loop unrolling
   PGAC_PROG_CC_VAR_OPT(CFLAGS_UNROLL_LOOPS, [-funroll-loops])
   # Optimization flags for specific files that benefit from vectorization
-- 
2.27.0


pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: Optionally automatically disable logical replication subscriptions on error
Next
From: Nitin Jadhav
Date:
Subject: Re: Report checkpoint progress with pg_stat_progress_checkpoint (was: Report checkpoint progress in server logs)