[Asterisk-code-review] pjsip distributor.c: Fix off-nominal tdata ref leak. (asterisk[13])

Mark Michelson asteriskteam at digium.com
Wed Feb 15 09:56:18 CST 2017


Mark Michelson has posted comments on this change. ( https://gerrit.asterisk.org/4924 )

Change subject: pjsip_distributor.c: Fix off-nominal tdata ref leak.
......................................................................


Patch Set 1:

> > > > So, it's a theoretical?
 > > > >
 > > > > The return value should match an enum, if not then they are
 > > > > violating the contract.
 > > >
 > > > Should still code for that path.  This patch make sure and we
 > > won't
 > > > wind up with dead code to satisfy the compiler.
 > >
 > > I don't understand this. Asterisk developers code with -Wall
 > (which
 > > includes -Wswitch) and -Werror. This means that if there is an
 > > enumeration case that is not present in a switch statement, or if
 > > there is a case that is outside the range of the enumeration you
 > > are switching on, the compiler will throw a warning, which will
 > > then be promoted to an error.
 > 
 > Compile the below code in file.c using "gcc -Wall -O2 file.c":
 > 
 > enum my_enum {
 > ONE,
 > TWO,
 > THREE,
 > };
 > 
 > int foo(enum my_enum bar);
 > 
 > int foo(enum my_enum bar)
 > {
 > int not_init;
 > 
 > switch (bar) {
 > case ONE:
 > not_init = 1;
 > break;
 > case TWO:
 > not_init = 2;
 > break;
 > case THREE:
 > not_init = 3;
 > break;
 > }
 > 
 > return not_init;
 > }
 > 
 > You get a warning about not_init maybe uninitialized because a
 > switch statement always has a default path even though all the enum
 > values are covered.

Okay, so it's not an error in how we're coding it. It's the fact that gcc's -Wswitch and -Wmaybe-uninitialized don't play well together.

-- 
To view, visit https://gerrit.asterisk.org/4924
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I571f371d0956a8039b197b4dbd8af6b18843598d
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-HasComments: No



More information about the asterisk-code-review mailing list