alac_file *alac_create(int samplesize, int numchannels) {
alac_file *newfile = malloc(sizeof(alac_file));
-
- memset(newfile, 0, sizeof(alac_file));
-
- newfile->samplesize = samplesize;
- newfile->numchannels = numchannels;
- newfile->bytespersample = (samplesize / 8) * numchannels;
-
+ if (newfile) {
+ memset(newfile, 0, sizeof(alac_file));
+ newfile->samplesize = samplesize;
+ newfile->numchannels = numchannels;
+ newfile->bytespersample = (samplesize / 8) * numchannels;
+ } else {
+ fprintf(stderr, "FIXME: can not allocate memory for a new file in alac_cxreate.");
+ }
return newfile;
}
return strdup(string);
newstr = strdup(string);
head = newstr;
- while ((tok = strstr(head, substr))) {
- oldstr = newstr;
- newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
- /*failed to alloc mem, free old string and return NULL */
- if (newstr == NULL) {
+ if (head) {
+ while ((tok = strstr(head, substr))) {
+ oldstr = newstr;
+ newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
+ /*failed to alloc mem, free old string and return NULL */
+ if (newstr == NULL) {
+ free(oldstr);
+ return NULL;
+ }
+ memcpy(newstr, oldstr, tok - oldstr);
+ memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
+ memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr),
+ strlen(oldstr) - strlen(substr) - (tok - oldstr));
+ memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
+ /* move back head right after the last replacement */
+ head = newstr + (tok - oldstr) + strlen(replacement);
free(oldstr);
- return NULL;
}
- memcpy(newstr, oldstr, tok - oldstr);
- memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
- memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr),
- strlen(oldstr) - strlen(substr) - (tok - oldstr));
- memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
- /* move back head right after the last replacement */
- head = newstr + (tok - oldstr) + strlen(replacement);
- free(oldstr);
+ } else {
+ die("failed to allocate memory in str_replace.");
}
return newstr;
}
void ranarrayinit() {
ranarray = (uint64_t *)malloc(ranarraylength * sizeof(uint64_t));
- int i;
- for (i = 0; i < ranarraylength; i++)
- ranarray[i] = r64u();
- ranarraynext = 0;
+ if (ranarray) {
+ int i;
+ for (i = 0; i < ranarraylength; i++)
+ ranarray[i] = r64u();
+ ranarraynext = 0;
+ } else {
+ die("failed to allocate space for the ranarray.");
+ }
}
uint64_t ranarrayval() {
static int nconns = 0;
static void track_thread(rtsp_conn_info *conn) {
conns = realloc(conns, sizeof(rtsp_conn_info *) * (nconns + 1));
- conns[nconns] = conn;
- nconns++;
+ if (conns) {
+ conns[nconns] = conn;
+ nconns++;
+ } else {
+ die("could not reallocate memnory for \"conns\" in rtsp.c.");
+ }
}
static void cleanup_threads(void) {
static rtsp_message *msg_init(void) {
rtsp_message *msg = malloc(sizeof(rtsp_message));
- memset(msg, 0, sizeof(rtsp_message));
- msg->referenceCount = 1; // from now on, any access to this must be protected with the lock
+ if (msg) {
+ memset(msg, 0, sizeof(rtsp_message));
+ msg->referenceCount = 1; // from now on, any access to this must be protected with the lock
+ } else {
+ die("can not allocate memory for an rtsp_message.");
+ }
return msg;
}