On 05/04/2017 11:52 AM, Martin Sebor wrote:
On 05/04/2017 10:00 AM, Prathamesh Kulkarni wrote:
Hi,
As mentioned in PR, the issue is that cddce1 marks the call to
__builtin_strdup as necessary:
marking necessary through .MEM_6 stmt p_7 = __builtin_strdup (&d);

and since p_7 doesn't get added to worklist in propagate_necessity()
because it's used only within free(), it's treated as "dead"
and wrongly gets released.
The patch fixes that by adding strdup/strndup in corresponding condition
in eliminate_unnecessary_stmts().

Another issue, was that my previous patch failed to remove multiple
calls to strdup:
char *f(char **tt)
{
  char *t = *tt;
  char *p;

  p = __builtin_strdup (t);
  p = __builtin_strdup (t);
  return p;

Since this is clearly a bug in the program -- the first result
leaks -- would it make sense to issue a warning before removing
the duplicate call?  (It would be nice to issue a warning not
just for strdup but also for other memory allocation functions,
so perhaps that should be a separate enhancement request.)
Seems like it should be a separate enhancement request.

jeff

Reply via email to