if (len <= 0)
len = 1;
if (bufsize < len) {
- buf = realloc(buf, len + ALIGN_LEN);
- if (buf == NULL) {
+ void *tmp;
+ tmp = realloc(buf, len + ALIGN_LEN);
+ if (tmp == NULL) {
+ free(buf);
save_errno = errno;
perror("allocating buf for read\n");
exit(save_errno);
}
+ buf = tmp;
bufsize = len;
buf_align = (char *)((long)(buf + ALIGN_LEN) &
~ALIGN_LEN);
if (len <= 0)
len = 1;
if (bufsize < len) {
- buf = realloc(buf, len + ALIGN_LEN);
- if (buf == NULL) {
+ void *tmp;
+ tmp = realloc(buf, len + ALIGN_LEN);
+ if (tmp == NULL) {
+ free(buf);
save_errno = errno;
perror("allocating buf for write\n");
exit(save_errno);
}
+ buf = tmp;
bufsize = len;
buf_align = (char *)((long)(buf + ALIGN_LEN) &
~ALIGN_LEN);
struct gssd_k5_kt_princ *ple;
/* Assume failure */
- retval = -1;
- *list = (char **) NULL;
+ *list = NULL;
/* Refresh machine credentials */
- if ((retval = gssd_refresh_krb5_machine_creds())) {
+ retval = gssd_refresh_krb5_machine_creds();
+ if (retval)
goto out;
- }
- if ((l = (char **) malloc(listsize * sizeof(char *))) == NULL) {
+ l = malloc(listsize * sizeof(char *));
+ if (l == NULL) {
retval = ENOMEM;
goto out;
}
for (ple = gssd_k5_kt_princ_list; ple; ple = ple->next) {
if (ple->ccname) {
if (i + 1 > listsize) {
+ void *tmp;
+
listsize += listinc;
- l = (char **)
- realloc(l, listsize * sizeof(char *));
- if (l == NULL) {
+ tmp = realloc(l, listsize * sizeof(char *));
+ if (tmp == NULL) {
retval = ENOMEM;
- goto out;
+ goto out_free;
}
+ l = tmp;
}
- if ((l[i++] = strdup(ple->ccname)) == NULL) {
+ l[i] = strdup(ple->ccname);
+ if (l[i++] == NULL) {
retval = ENOMEM;
- goto out;
+ goto out_free;
}
}
}
if (i > 0) {
l[i] = NULL;
*list = l;
- retval = 0;
- goto out;
+ return 0;
}
- out:
+out_free:
+ while (i > 0)
+ free(l[i--]);
+ free(l);
+out:
return retval;
}
/* extract the 3 fields */
rc = sscanf(start, "%x-%x/%u", &lo, &hi, &step);
switch (rc) {
- case 0: {
- return 0;
- }
- case 1: {
- array_sz++;
- *array = realloc(*array, array_sz * sizeof(int));
- if (*array == NULL)
- return 0;
+ case 0:
+ goto err;
+ case 1: {
+ void *tmp;
+
+ array_sz++;
+ tmp = realloc(*array, array_sz * sizeof(int));
+ if (tmp == NULL)
+ goto err;
+ *array = tmp;
(*array)[array_idx] = lo;
array_idx++;
break;
/* do not break to share code with case 3: */
}
case 3: {
- if ((hi < lo) || (step == 0))
- return 0;
- array_sz += (hi - lo) / step + 1;
- *array = realloc(*array, sizeof(int) * array_sz);
- if (*array == NULL)
- return 0;
+ void *tmp;
+
+ if ((hi < lo) || (step == 0))
+ goto err;
+ array_sz += (hi - lo) / step + 1;
+ tmp = realloc(*array, array_sz * sizeof(int));
+ if (tmp == NULL)
+ goto err;
+ *array = tmp;
for (i = lo; i <= hi; i+=step, array_idx++)
(*array)[array_idx] = i;
break;
} while (ptr != NULL);
return array_sz;
+err:
+ if (*array != NULL) {
+ free(*array);
+ *array = NULL;
+ }
+ return 0;
}
static int extract_fsname_poolname(char *arg, char *fsname, char *poolname)