some printf leaks

This commit is contained in:
Jack Halford 2016-11-16 18:33:01 +01:00
parent b7ce8460ff
commit 8d1ece5280
21 changed files with 73 additions and 57 deletions

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* btree.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/16 11:13:15 by jhalford #+# #+# */
/* Updated: 2016/11/16 11:14:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BTREE_H
# define BTREE_H

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/19 12:06:15 by jhalford #+# #+# */
/* Updated: 2016/08/23 17:49:17 by jhalford ### ########.fr */
/* Updated: 2016/11/16 11:14:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
/* Updated: 2016/11/14 18:26:32 by jhalford ### ########.fr */
/* Updated: 2016/11/16 11:24:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,9 +15,12 @@
static void print_offset(int offset)
{
int i;
for (i = 0; i < offset; ++i)
i = 0;
while (i < offset)
{
ft_putstr(" ");
i++;
}
}
@ -26,14 +29,12 @@ void btree_print(t_btree* tree, void (*printer)(t_btree *tree))
static int offset = 0;
print_offset(offset);
if (tree == NULL)
{
ft_putendl("-");
return ;
}
(*printer)(tree);
offset += 3;
btree_print(tree->right, printer);
btree_print(tree->left, printer);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:55:40 by jhalford #+# #+# */
/* Updated: 2016/11/14 17:57:46 by jhalford ### ########.fr */
/* Updated: 2016/11/16 11:15:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 14:30:00 by jhalford #+# #+# */
/* Updated: 2016/11/10 14:30:27 by jhalford ### ########.fr */
/* Updated: 2016/11/16 11:24:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,6 @@ char *ft_getenv(char **env, char *key)
return (NULL);
while (*env)
{
/* ft_printf("%s\n", env[i]); */
if (ft_strcmp(*env, key) == '=')
return (*env + ft_strlen(key) + 1);
env++;

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
/* Updated: 2016/11/10 12:59:25 by jhalford ### ########.fr */
/* Updated: 2016/11/16 18:30:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,9 +33,9 @@ char *ft_unsigned_conversion(t_fmt *fmt, va_list ap)
while (fmt->conversion != g_convs[i].id)
i++;
if (!*fmt->modifier
|| ft_strcmp(fmt->modifier, "hh") == 0
|| ft_strcmp(fmt->modifier, "h") == 0
|| ft_strcmp(fmt->modifier, "z") == 0)
|| ft_strequ(fmt->modifier, "hh")
|| ft_strequ(fmt->modifier, "h")
|| ft_strequ(fmt->modifier, "z"))
{
uiarg = va_arg(ap, int);
return (ft_uitoa_base(uiarg, g_convs[i].base));

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */
/* Updated: 2016/11/10 13:02:07 by jhalford ### ########.fr */
/* Updated: 2016/11/16 11:15:55 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,7 +46,6 @@ static void ft_fmt_validate_flag_conv(t_fmt *fmt)
if (!ft_strchr(g_convs[i].allowed_flags, flag))
{
ft_fmt_error_flag_conv(flag, fmt->conversion);
/* ft_printf("allowed flags:%s\n", g_convs[i].allowed_flags); */
if (flag == '#')
*flag_ptr = '.';
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
/* Updated: 2016/11/16 10:58:04 by jhalford ### ########.fr */
/* Updated: 2016/11/16 18:30:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,7 @@ int ft_printf(const char *format, ...)
va_list ap;
va_start(ap, format);
return(ft_vdprintf(0, format, ap));
return (ft_vdprintf(1, format, ap));
}
int ft_dprintf(int fd, const char *format, ...)
@ -44,10 +44,11 @@ int ft_dprintf(int fd, const char *format, ...)
int ft_vdprintf(int fd, const char *format, va_list ap)
{
char *str;
char *transform;
char final[1000];
t_fmt *fmt;
str = ft_strdup(format);
str = (char *)format;
ft_bzero(final, 1000);
while (*str)
{
@ -59,12 +60,16 @@ int ft_vdprintf(int fd, const char *format, va_list ap)
if (!fmt->valid)
ft_strncat(final, &fmt->conversion, 1);
else
ft_strcat(final, ft_transform(fmt, ap));
{
transform = ft_transform(fmt, ap);
ft_strcat(final, transform);
free(transform);
}
free(fmt);
}
else
ft_strncat(final, str++, 1);
}
ft_putstr_fd(final, fd);
ft_strdel(&str);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
/* Updated: 2016/11/07 16:40:15 by jhalford ### ########.fr */
/* Updated: 2016/11/16 17:56:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,6 @@
char *ft_transform(t_fmt *fmt, va_list ap)
{
char *buf;
char *ret;
int i;
@ -24,11 +23,7 @@ char *ft_transform(t_fmt *fmt, va_list ap)
fmt->conv = g_convs[i];
ret = (*fmt->conv.converter)(fmt, ap);
if (fmt->width > (int)ft_strlen(ret))
{
buf = ret;
ret = (char *)malloc(sizeof(char) * (fmt->width + 5));
ft_strcpy(ret, buf);
}
ret = ft_realloc(ret, fmt->width + 5);
if (ft_strchr(fmt->flags, '-'))
ft_pad_right(ret, fmt);
else

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
/* Updated: 2016/11/07 17:22:26 by jhalford ### ########.fr */
/* Updated: 2016/11/16 17:46:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
/* Updated: 2016/11/08 10:18:08 by jhalford ### ########.fr */
/* Updated: 2016/11/16 18:13:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,7 +24,7 @@ void ft_pad_left(char *str, t_fmt *fmt)
{
char sign;
sign = '\0';
sign = 0;
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
{
sign = str[0];

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
/* Updated: 2016/11/08 10:18:20 by jhalford ### ########.fr */
/* Updated: 2016/11/16 17:56:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
/* Updated: 2016/11/14 16:55:27 by jhalford ### ########.fr */
/* Updated: 2016/11/16 18:23:24 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,6 +28,7 @@ void ft_lst_delif(
{
tmp = (*indirect);
(*indirect) = (*indirect)->next;
ft_printf("free'd at %p\n", tmp);
(*del)(tmp->content, tmp->content_size);
}
else

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:30 by jhalford #+# #+# */
/* Updated: 2016/11/08 11:52:33 by jhalford ### ########.fr */
/* Updated: 2016/11/16 14:00:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */
/* Updated: 2016/11/08 13:36:19 by jhalford ### ########.fr */
/* Updated: 2016/11/16 18:24:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,11 @@
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
{
if (alst && *alst && (*alst)->next)
if (alst && *alst && del)
{
ft_printf("free'd at %p\n", *alst);
ft_lstdel(&(*alst)->next, del);
ft_lstdelone(alst, del);
*alst = NULL;
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */
/* Updated: 2016/11/14 15:50:00 by jhalford ### ########.fr */
/* Updated: 2016/11/16 18:22:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,6 +19,6 @@ void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
if (del)
(*del)((*alst)->content, (*alst)->content_size);
free(*alst);
}
*alst = NULL;
}
}

View file

@ -6,14 +6,17 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:57:33 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:57:33 by jhalford ### ########.fr */
/* Updated: 2016/11/16 12:23:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_memdel(void **ap)
{
if (ap && *ap)
{
free(*ap);
*ap = NULL;
}
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:37:53 by jhalford #+# #+# */
/* Updated: 2016/11/11 17:41:30 by jhalford ### ########.fr */
/* Updated: 2016/11/16 17:56:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,10 +16,8 @@ void *ft_realloc(void *data, int size)
{
void *new;
ft_printf("realloc befor: '%s'\n", data);
new = ft_memalloc(size);
ft_memcpy(new, data, ft_strlen(data));
ft_memdel(&data);
ft_printf("realloc after: '%s'\n", new);
return (new);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:45:07 by jhalford #+# #+# */
/* Updated: 2016/11/04 11:45:08 by jhalford ### ########.fr */
/* Updated: 2016/11/16 12:07:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 15:46:03 by jhalford #+# #+# */
/* Updated: 2016/11/07 15:46:11 by jhalford ### ########.fr */
/* Updated: 2016/11/16 17:58:02 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/03 14:58:43 by jhalford #+# #+# */
/* Updated: 2016/11/03 14:58:43 by jhalford ### ########.fr */
/* Updated: 2016/11/16 17:52:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,8 +17,7 @@ char *ft_strsub(char const *s, unsigned int start, size_t len)
char *out;
size_t i;
out = (char *)malloc(sizeof(char) * (len + 1));
if (!out)
if (!(out = (char *)malloc(sizeof(char) * (len + 1))))
return (NULL);
i = -1;
while (++i < len)