search for: safe_realloc

Displaying 20 results from an estimated 88 matches for "safe_realloc".

2015 Jun 04
3
[PATCH] Use safe_realloc() in favor of realloc overall.
...2,11 +1220,7 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, size_t n = fs->nr_fstab + 1; struct inspect_fstab_entry *p; - p = realloc (fs->fstab, n * sizeof (struct inspect_fstab_entry)); - if (p == NULL) { - perrorf (g, "realloc"); - return -1; - } + p = safe_realloc (g, fs->fstab, n * sizeof (struct inspect_fstab_entry)); fs->fstab = p; fs->nr_fstab = n; @@ -1236,8 +1230,6 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, fs->fstab[n-1].mountpoint = safe_strdup (g, mountpoint); debug (g, "fstab: mountable=%s mountpoint=%...
2015 Jun 02
2
Re: [PATCH 2/3] inspection: Add support for CoreOS
...gt; + guestfs_int_free_inspect_info (g); >> + return NULL; >> + } > Although this is stylistic, I think it's easier to understand if > you change the if condition to: > > if (collect_coreos_inspection_info (g) == -1) { > ... > Since we 'll be using safe_realloc, I don't think there is a need for any of: * guestfs_int_merge_fs_inspections() * collect_coreos_inspection_info() to be returning a value at all. So, I'll remove the if check completely. Nikos P.S. You have a check like this one on guestfs_int_check_for_filesystem_on() a few lines abov...
2015 Jun 02
2
Re: [PATCH 2/3] inspection: Add support for CoreOS
...NULL; >>>> + } >>> Although this is stylistic, I think it's easier to understand if >>> you change the if condition to: >>> >>> if (collect_coreos_inspection_info (g) == -1) { >>> ... >>> >> Since we 'll be using safe_realloc, I don't think there is a need for >> any of: >> * guestfs_int_merge_fs_inspections() >> * collect_coreos_inspection_info() >> to be returning a value at all. So, I'll remove the if check completely. >> >> Nikos >> >> P.S. You have a check l...
2015 May 29
2
[PATCH 1/3] inspection: Add func for merging fs inspections
Add a new guestfs_int_merge_fs_inspections() function that merges the OS inspection information of two inspect_fs instances into one. This function is useful if the inspection information for an OS are gathered by inspecting multiple filesystems. Signed-off-by: Nikos Skalkotos <skalkoto@grnet.gr> --- src/guestfs-internal.h | 1 + src/inspect-fs.c | 115
2015 Jun 02
1
[PATCH 1/3] inspection: Add func for merging fs inspections
...src->drive_mappings; + src->drive_mappings = NULL; + } else { + n = 0; + for (; dst->drive_mappings[n] != NULL; n++) + ; + old = n; + for (; src->drive_mappings[n] != NULL; n++) + ; + + /* Merge the src mappings to dst */ + mappings = safe_realloc (g, dst->drive_mappings,(n + 1) * sizeof (char *)); + + for (i = old; i < n; i++) + mappings[i] = src->drive_mappings[i - old]; + + mappings[n] = NULL; + dst->drive_mappings = mappings; + + free(src->drive_mappings); + src->drive_mappings = NULL; +...
2016 Mar 29
3
[PATCH 0/2] added filesystem_walk API
The filesystem_walk API parses the FS internals of a partition and returns a list of all the files and directories contained within. It list deleted files and directories as well. For each node, it reports its relative path, its inode and its allocation status. This is the end user API for inspecting a disk partition content. The command can handle filenames with special characters. Example
2016 Mar 29
0
[PATCH 1/2] added filesystem_walk API
...lloc(g, sizeof *nodes); + nodes->len = 0; + nodes->val = NULL; + + xdrmem_create(&xdr, buf, bufsize, XDR_DECODE); + + for (index = 0; xdr_getpos(&xdr) < bufsize; index++) { + if (index == nodes->len) { + nodes->len = 2 * (nodes->len + 1); + nodes->val = safe_realloc(g, nodes->val, + nodes->len * sizeof (struct guestfs_tsk_node)); + } + + if (deserialise_inode_info(g, &xdr, &nodes->val[index]) < 0) + { + xdr_destroy(&xdr); + free_nodes(nodes); + + return NULL; + } + } +...
2016 Apr 03
0
[PATCH v2 4/5] appliance: Added filesystem_walk command
...Deserialise buffer into dirent list. */ + ret = deserialise_dirent_list (g, buf, bufsize, &dirents); + if (ret < 0) { + guestfs_free_tsk_dirent_list (dirents); + return NULL; + } + + /* Resize the array to correct number of entries. */ + dirents->len = ret; + dirents->val = safe_realloc (g, dirents->val, + dirents->len * + sizeof (struct guestfs_tsk_dirent)); + + return dirents; +} + +/* Deserialise buf content and populate the dirent list. + * Return the number of deserialised dirents, -1 on error. + */ +int +dese...
2012 Oct 29
1
[PATCH] lib: update inspect_list_applications to return all installed RPMs (RHBZ#859885)
...ar *name; /* Ignore bogus entries. */ if (keylen == 0 || valuelen < 4) return 0; - /* The name (key) field won't be NUL-terminated, so we must do that. */ - name = safe_malloc (g, keylen+1); - memcpy (name, key, keylen); - name[keylen] = '\0'; - - list->names = safe_realloc (g, list->names, - (list->len + 1) * sizeof (struct rpm_name)); - list->names[list->len].name = name; - memcpy (list->names[list->len].link, value, 4); - list->len++; + /* A name entry will have as many links as installed instances of + * that...
2016 Apr 04
2
Re: [PATCH v2 4/5] appliance: Added filesystem_walk command
...+ ret = deserialise_dirent_list (g, buf, bufsize, &dirents); > + if (ret < 0) { > + guestfs_free_tsk_dirent_list (dirents); > + return NULL; > + } > + > + /* Resize the array to correct number of entries. */ > + dirents->len = ret; > + dirents->val = safe_realloc (g, dirents->val, > + dirents->len * > + sizeof (struct guestfs_tsk_dirent)); You don't need to shrink the array with values -- users knows already they don't have to access it past 'len' values. > + > +...
2015 Jun 02
0
Re: [PATCH 1/3] inspection: Add func for merging fs inspections
...); > + if (fstab == NULL) { > + perrorf (g, "realloc"); > + return -1; > + } These both leak the original pointers on failure, and also leave the dst / src structures in a half-merged state. Since allocation failures are unlikely to be recoverable, just call `safe_realloc (g, ...)' instead. It calls the per-handle out of memory handler (guestfs_set_out_of_memory_handler) on failure. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts ph...
2015 Jun 02
0
Re: [PATCH 2/3] inspection: Add support for CoreOS
...gt; >> + return NULL; > >> + } > > Although this is stylistic, I think it's easier to understand if > > you change the if condition to: > > > > if (collect_coreos_inspection_info (g) == -1) { > > ... > > > Since we 'll be using safe_realloc, I don't think there is a need for > any of: > * guestfs_int_merge_fs_inspections() > * collect_coreos_inspection_info() > to be returning a value at all. So, I'll remove the if check completely. > > Nikos > > P.S. You have a check like this one on > guestfs_i...
2015 Jun 02
0
Re: [PATCH 2/3] inspection: Add support for CoreOS
...src/inspect-fs.c: static int extend_fses (guestfs_h *g) { size_t n = g->nr_fses + 1; struct inspect_fs *p; p = realloc (g->fses, n * sizeof (struct inspect_fs)); if (p == NULL) { perrorf (g, "realloc"); return -1; } Should probably just call safe_realloc .. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
2015 Jun 02
1
Re: [PATCH 2/3] inspection: Add support for CoreOS
...fs_h *g) > { > size_t n = g->nr_fses + 1; > struct inspect_fs *p; > > p = realloc (g->fses, n * sizeof (struct inspect_fs)); > if (p == NULL) { > perrorf (g, "realloc"); > return -1; > } > > Should probably just call safe_realloc .. > > Rich. >
2009 Aug 03
0
[PATCH] guestfs: fix typo in my recent change
..._h *g, const char *fs, ...) #ifndef _GNU_SOURCE char buf[256]; - strerror_r (err, buf, sizeof buf); + strerror_r (errnum, buf, sizeof buf); #else char _buf[256]; char *buf; - buf = strerror_r (err, _buf, sizeof _buf); + buf = strerror_r (errnum, _buf, sizeof _buf); #endif msg = safe_realloc (g, msg, strlen (msg) + 2 + strlen (buf) + 1); -- 1.6.4.212.g4719
2009 Nov 18
1
[PATCH] generator: Fix API of functions that return RBufferOut
...ot;, "\ This command lets you read part of a file. It reads C<count> @@ -5107,7 +5109,7 @@ and generate_client_actions () = #define error guestfs_error //#define perrorf guestfs_perrorf -//#define safe_malloc guestfs_safe_malloc +#define safe_malloc guestfs_safe_malloc #define safe_realloc guestfs_safe_realloc //#define safe_strdup guestfs_safe_strdup #define safe_memdup guestfs_safe_memdup @@ -5396,8 +5398,20 @@ check_state (guestfs_h *g, const char *caller) pr " /* caller will free this */\n"; pr " return safe_memdup (g, &ret.%s, sizeo...
2016 Apr 05
1
Re: [PATCH v3 4/5] appliance: Added filesystem_walk command
...0; > + uint32_t index = 0; > + > + xdrmem_create (&xdr, buf, bufsize, XDR_DECODE); > + > + for (index = 0; xdr_getpos (&xdr) < bufsize; index++) { > + if (index == dirents->len) { > + dirents->len = 2 * dirents->len; > + dirents->val = safe_realloc (g, dirents->val, > + dirents->len * > + sizeof (*dirents->val)); > + } > + > + memset(&dirents->val[index], 0, sizeof (*dirents->val)); I think this should not be needed at all, the XDR dec...
2015 Sep 29
2
[PATCH 1/2] copy-in: print tar stderr when it fails
...drain_fd (guestfs_h *g, int fd, char **ret) +{ + char *data = NULL; + size_t size = 0; + size_t n = 0; + size_t left = 0; + ssize_t r; + + while (1) { + size_t to_read; + if (left > 0) { + to_read = left; + } else { + to_read = 1024; + size += to_read; + data = safe_realloc (g, data, size); + } + r = read (fd, &data[n], to_read); + if (r == -1) { + perrorf (g, _("drain_fd: read")); + free (data); + close (fd); + return -1; + } + if (r == 0) + break; + n += r; + left = 1024 - r; + } + + if (close (fd) == -1)...
2012 Oct 18
10
[PATCH 0/10] Add a mini-library for running external commands.
Inspired by libvirt's virCommand* internal mini-library, this adds some internal APIs for running commands. The first patch contains the new APIs. The subsequent patches change various parts of the library over to use it. Rich.
2016 Nov 09
0
[PATCH v2 5/6] New API: yara_scan
...(fp), &statbuf); + if (ret == -1) + return -1; + + xdrstdio_create (&xdr, fp, XDR_DECODE); + + for (index = 0; xdr_getpos (&xdr) < statbuf.st_size; index++) { + if (index == detections->len) { + detections->len = 2 * detections->len; + detections->val = safe_realloc (g, detections->val, + detections->len * + sizeof (*detections->val)); + } + + /* Clear the entry so xdr logic will allocate necessary memory. */ + memset (&detections->val[index], 0, sizeof (*detecti...