Skip to content

Commit

Permalink
compose/postprocess: Fix memleak in error path, minor style update
Browse files Browse the repository at this point in the history
Using an autoptr for the strbuf not only fixes a memleak in the error path, it's
a bit more efficient since we can just pass `buf->len` rather than running
`strlen()`.

Closes: #1042
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Oct 6, 2017
1 parent 7c4c2c6 commit b383ef8
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/libpriv/rpmostree-postprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,12 @@ convert_var_to_tmpfiles_d_recurse (GOutputStream *tmpfiles_out,
while (TRUE)
{
struct dirent *dent = NULL;
GString *tmpfiles_d_buf;
g_autofree char *tmpfiles_d_line = NULL;
char filetype_c;

if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error))
return FALSE;

if (!dent)
break;

char filetype_c;
switch (dent->d_type)
{
case DT_DIR:
Expand All @@ -459,7 +455,7 @@ convert_var_to_tmpfiles_d_recurse (GOutputStream *tmpfiles_out,
continue;
}

tmpfiles_d_buf = g_string_new ("");
g_autoptr(GString) tmpfiles_d_buf = g_string_new ("");
g_string_append_c (tmpfiles_d_buf, filetype_c);
g_string_append_c (tmpfiles_d_buf, ' ');
g_string_append (tmpfiles_d_buf, prefix->str);
Expand Down Expand Up @@ -506,10 +502,8 @@ convert_var_to_tmpfiles_d_recurse (GOutputStream *tmpfiles_out,

g_string_append_c (tmpfiles_d_buf, '\n');

tmpfiles_d_line = g_string_free (tmpfiles_d_buf, FALSE);

if (!g_output_stream_write_all (tmpfiles_out, tmpfiles_d_line,
strlen (tmpfiles_d_line), &bytes_written,
if (!g_output_stream_write_all (tmpfiles_out, tmpfiles_d_buf->str,
tmpfiles_d_buf->len, &bytes_written,
cancellable, error))
return FALSE;
}
Expand Down

0 comments on commit b383ef8

Please sign in to comment.