]> git.alsa-project.org Git - alsa-lib.git/commitdiff
- check the return value of malloc & co.
authorTakashi Iwai <tiwai@suse.de>
Wed, 25 Feb 2004 11:24:29 +0000 (11:24 +0000)
committerTakashi Iwai <tiwai@suse.de>
Wed, 25 Feb 2004 11:24:29 +0000 (11:24 +0000)
src/conf.c
src/pcm/pcm_adpcm.c
src/pcm/pcm_direct.c
src/pcm/pcm_ladspa.c
src/pcm/pcm_multi.c
src/pcm/pcm_share.c
src/pcm/pcm_shm.c

index 7c5f9935966ba535745ddbb91d64f48f73fc59bb..6c142197b713cd887a081e81d13617214705e913 100644 (file)
@@ -2642,6 +2642,10 @@ static int snd_config_hooks_call(snd_config_t *root, snd_config_t *config, snd_c
        if (!func_name) {
                int len = 16 + strlen(str) + 1;
                buf = malloc(len);
+               if (! buf) {
+                       err = -ENOMEM;
+                       goto _err;
+               }
                snprintf(buf, len, "snd_config_hook_%s", str);
                buf[len-1] = '\0';
                func_name = buf;
@@ -3423,6 +3427,10 @@ static int _snd_config_evaluate(snd_config_t *src,
                if (!func_name) {
                        int len = 9 + strlen(str) + 1;
                        buf = malloc(len);
+                       if (! buf) {
+                               err = -ENOMEM;
+                               goto _err;
+                       }
                        snprintf(buf, len, "snd_func_%s", str);
                        buf[len-1] = '\0';
                        func_name = buf;
index 235163a02c12fb9626d13c5c095d137acaa5abcf..1b824a9f38e719cf886b5299eebfaa81575075cf 100644 (file)
@@ -439,6 +439,8 @@ static int snd_pcm_adpcm_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
        }
        assert(!adpcm->states);
        adpcm->states = malloc(adpcm->plug.slave->channels * sizeof(*adpcm->states));
+       if (adpcm->states == NULL)
+               return -ENOMEM;
        return 0;
 }
 
index 33c3e6ddf372e68be8f1922fb9317ed0c43499f6..3b748d36180ae0de3f675385d45b037edc887fa3 100644 (file)
@@ -923,6 +923,8 @@ int snd_pcm_direct_parse_bindings(snd_pcm_direct_t *dmix, snd_config_t *cfg)
                return -EINVAL;
        }
        dmix->bindings = malloc(count * sizeof(unsigned int));
+       if (dmix->bindings == NULL)
+               return -ENOMEM;
        for (chn = 0; chn < count; chn++)
                dmix->bindings[chn] = UINT_MAX;         /* don't route */
        snd_config_for_each(i, next, cfg) {
index 6051a0de0ef75dc275f7cff96d55db0d8f04452b..3b80225df0f49a0d3f974495373229acd35e97eb 100644 (file)
@@ -771,6 +771,8 @@ static int snd_pcm_ladspa_check_dir(snd_pcm_ladspa_plugin_t * const plugin,
                }
                
                filename = malloc(len + strlen(dirent->d_name) + 1 + need_slash);
+               if (filename == NULL)
+                       return -ENOMEM;
                strcpy(filename, path);
                if (need_slash)
                        strcat(filename, "/");
@@ -880,6 +882,8 @@ static int snd_pcm_ladspa_parse_ioconfig(snd_pcm_ladspa_plugin_t *lplug,
                }
                if (count > 0) {
                        array = (unsigned int *)calloc(count, sizeof(unsigned int));
+                       if (! array)
+                               return -ENOMEM;
                        memset(array, 0xff, count * sizeof(unsigned int));
                        io->port_bindings_size = count;
                        io->port_bindings = array;
@@ -928,6 +932,8 @@ static int snd_pcm_ladspa_parse_ioconfig(snd_pcm_ladspa_plugin_t *lplug,
                        if ((lplug->desc->PortDescriptors[idx] & (io->pdesc | LADSPA_PORT_CONTROL)) == (io->pdesc | LADSPA_PORT_CONTROL))
                                count++;
                array = (LADSPA_Data *)calloc(count, sizeof(LADSPA_Data));
+               if (!array)
+                       return -ENOMEM;
                io->controls_size = count;
                io->controls = array;
                snd_config_for_each(i, next, controls) {
index 2a530bf5974ddedf28b9109e0fe321bf5e98604f..0f047ecf56299494bda8d7eb8b7e110cf370f5e1 100644 (file)
@@ -696,8 +696,17 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
        multi->slaves_count = slaves_count;
        multi->master_slave = master_slave;
        multi->slaves = calloc(slaves_count, sizeof(*multi->slaves));
+       if (!multi->slaves) {
+               free(multi);
+               return -ENOMEM;
+       }
        multi->channels_count = channels_count;
        multi->channels = calloc(channels_count, sizeof(*multi->channels));
+       if (!multi->channels) {
+               free(multi->slaves);
+               free(multi->channels);
+               return -ENOMEM;
+       }
        for (i = 0; i < slaves_count; ++i) {
                snd_pcm_multi_slave_t *slave = &multi->slaves[i];
                assert(slaves_pcm[i]->stream == stream);
@@ -914,6 +923,11 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
        slaves_channels = calloc(slaves_count, sizeof(*slaves_channels));
        channels_sidx = calloc(channels_count, sizeof(*channels_sidx));
        channels_schannel = calloc(channels_count, sizeof(*channels_schannel));
+       if (!slaves_id || !slaves_conf || !slaves_pcm || !slaves_channels ||
+           !channels_sidx || !channels_schannel) {
+               err = -ENOMEM;
+               goto _free;
+       }
        idx = 0;
        for (idx = 0; idx < channels_count; ++idx)
                channels_sidx[idx] = -1;
@@ -1036,6 +1050,8 @@ _free:
                free(channels_sidx);
        if (channels_schannel)
                free(channels_schannel);
+       if (slaves_id)
+               free(slaves_id);
        return err;
 }
 #ifndef DOC_HIDDEN
index 8b9784001021508fd4edd9ffce0ec23466e1b4c0..8922013588bccc47425adfddf1559fc4e6d83e14 100644 (file)
@@ -1630,6 +1630,10 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name,
                goto _free;
        }
        channels_map = calloc(channels, sizeof(*channels_map));
+       if (! channels_map) {
+               err = -ENOMEM;
+               goto _free;
+       }
 
        snd_config_for_each(i, next, bindings) {
                snd_config_t *n = snd_config_iterator_entry(i);
index ff7c722a5c15fe7f8afa9dfdf6c80cf4bb9f0a41..1c963affa6f842602ac68ddbb46b310adb3110b3 100644 (file)
@@ -795,6 +795,8 @@ int snd_is_local(struct hostent *hent)
        
        conf.ifc_len = numreqs * sizeof(struct ifreq);
        conf.ifc_buf = malloc((unsigned int) conf.ifc_len);
+       if (! conf.ifc_buf)
+               return -ENOMEM;
        while (1) {
                err = ioctl(s, SIOCGIFCONF, &conf);
                if (err < 0) {
@@ -806,6 +808,8 @@ int snd_is_local(struct hostent *hent)
                numreqs *= 2;
                conf.ifc_len = numreqs * sizeof(struct ifreq);
                conf.ifc_buf = realloc(conf.ifc_buf, (unsigned int) conf.ifc_len);
+               if (! conf.ifc_buf)
+                       return -ENOMEM;
        }
        numreqs = conf.ifc_len / sizeof(struct ifreq);
        for (i = 0; i < numreqs; ++i) {