Commit d6664eea authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

proc-parse: Add alloc_fhandle/free_fhandle helpers

This removes code duplication. There is no strong
need for free_fhandle but I decided to add it to
be consistent with alloc/free handlers.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8573f5ec
...@@ -831,6 +831,19 @@ static char nybble(const char n) ...@@ -831,6 +831,19 @@ static char nybble(const char n)
return 0; return 0;
} }
static int alloc_fhandle(FhEntry *fh)
{
fh->n_handle = FH_ENTRY_SIZES__min_entries;
fh->handle = xmalloc(pb_repeated_size(fh, handle));
return fh->handle == NULL ? -1 : 0;
}
static void free_fhandle(FhEntry *fh)
{
xfree(fh->handle);
}
static void parse_fhandle_encoded(char *tok, FhEntry *fh) static void parse_fhandle_encoded(char *tok, FhEntry *fh)
{ {
char *d = (char *)fh->handle; char *d = (char *)fh->handle;
...@@ -958,17 +971,14 @@ int parse_fdinfo(int fd, int type, ...@@ -958,17 +971,14 @@ int parse_fdinfo(int fd, int type,
if (ret != 7) if (ret != 7)
goto parse_err; goto parse_err;
f_handle.n_handle = FH_ENTRY_SIZES__min_entries; if (alloc_fhandle(&f_handle))
f_handle.handle = xmalloc(pb_repeated_size(&f_handle, handle));
if (!f_handle.handle)
return -1; return -1;
parse_fhandle_encoded(str + hoff, &f_handle); parse_fhandle_encoded(str + hoff, &f_handle);
entry.ffy.type = MARK_TYPE__INODE; entry.ffy.type = MARK_TYPE__INODE;
ret = cb(&entry, arg); ret = cb(&entry, arg);
xfree(f_handle.handle); free_fhandle(&f_handle);
if (ret) if (ret)
return ret; return ret;
...@@ -1021,16 +1031,13 @@ int parse_fdinfo(int fd, int type, ...@@ -1021,16 +1031,13 @@ int parse_fdinfo(int fd, int type,
if (ret != 7) if (ret != 7)
goto parse_err; goto parse_err;
f_handle.n_handle = FH_ENTRY_SIZES__min_entries; if (alloc_fhandle(&f_handle))
f_handle.handle = xmalloc(pb_repeated_size(&f_handle, handle));
if (!f_handle.handle)
return -1; return -1;
parse_fhandle_encoded(str + hoff, entry.ify.f_handle); parse_fhandle_encoded(str + hoff, entry.ify.f_handle);
ret = cb(&entry, arg); ret = cb(&entry, arg);
xfree(f_handle.handle); free_fhandle(&f_handle);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment