Re: PATCH: anti memleak part 4



On 2001.10.18 13:03 Ali Akcaagac wrote:
> oki, the last one for today.. i am getting bored now..
> hope that everything is correct so far. so please review
> and commit... it took me a while to do all this hope it
> wasnt for /dev/null :)

Again, a couple of comments:

> diff -ruN balsa-cvs/libbalsa/pop3.c balsa/libbalsa/pop3.c
> --- balsa-cvs/libbalsa/pop3.c	Thu Oct 18 16:38:17 2001
> +++ balsa/libbalsa/pop3.c	Thu Oct 18 18:59:33 2001
> @@ -149,9 +149,15 @@
>          finish = strchr(start, '>');
>          if (finish) {
>              strncpy(stamp, start, finish - start + 1);
> -            return TRUE;
> +
> +	    g_free(start);
> +	    g_free(finish);
> +	    return TRUE;
>          }
> +
> +	g_free(start);
>      }
> +
>      return FALSE;
>  }
> 

This would not be good.  Strchr returns a pointer into an existing 
string, not to a newly allocated string, so you would be freeing parts 
of `buff'.

...
> @@ -448,12 +454,15 @@
>  	}
>  	else
>  	    p = buffer;
> -	 
> +
>  	/* fwrite(p, 1, chunk, stdout); */
>  	if(fwrite (p, 1, (size_t) chunk, msg) != (size_t) chunk)
>              return POP_WRITE_ERR;
> +
> +	if(p != NULL)
> +	    g_free(p);
>      } /* end of while */
> -
> +
>      DM("POP3: Message %d retrieved", msgno);
>      return POP_OK;
>  }

Again, `p' is pointing to somewhere in `buffer', so it's an error to 
free it.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]