Skip to content

Commit 73718be

Browse files
committed
aplay/jack: avoid using alloca/strdup
+ small related improvements
1 parent 0e5af30 commit 73718be

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/audio/playback/jack.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,14 @@ static void audio_play_jack_help(const char *client_name)
153153

154154
static void * audio_play_jack_init(const char *cfg)
155155
{
156-
struct state_jack_playback *s;
157156
const char **ports;
158157
jack_status_t status;
159-
char *client_name;
158+
char client_name[STR_LEN];
160159
const char *source_name = "";
161160

162-
client_name = alloca(MAX(strlen(PACKAGE_NAME), strlen(cfg)) + 1);
163-
strcpy(client_name, PACKAGE_NAME);
161+
snprintf_ch(client_name, "%s", PACKAGE_NAME);
164162

165-
s = calloc(1, sizeof(struct state_jack_playback));
163+
struct state_jack_playback *s = calloc(1, sizeof(*s));
166164
if(!s) {
167165
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unable to allocate memory.\n");
168166
return NULL;
@@ -174,16 +172,16 @@ static void * audio_play_jack_init(const char *cfg)
174172
return NULL;
175173
}
176174

177-
char *dup = strdup(cfg);
178-
assert(dup != NULL);
175+
char dup[STR_LEN];
176+
snprintf_ch(dup, "%s", cfg);
179177
char *tmp = dup, *item, *save_ptr;
180178
while ((item = strtok_r(tmp, ":", &save_ptr)) != NULL) {
181179
if (strcmp(item, "help") == 0) {
182180
audio_play_jack_help(client_name);
183181
free(s);
184-
free(dup);
185182
return INIT_NOERR;
186-
} else if (strstr(item, "first_channel=") == item) {
183+
}
184+
if (strstr(item, "first_channel=") == item) {
187185
char *endptr;
188186
char *val = item + strlen("first_channel=");
189187
errno = 0;
@@ -200,8 +198,6 @@ static void * audio_play_jack_init(const char *cfg)
200198
}
201199
tmp = NULL;
202200
}
203-
free(dup);
204-
dup = NULL;
205201

206202
s->jack_ports_pattern = strdup(source_name);
207203

@@ -253,7 +249,6 @@ static void * audio_play_jack_init(const char *cfg)
253249
s->libjack->client_close(s->client);
254250
error:
255251
close_libjack(s->libjack);
256-
free(dup);
257252
free(s);
258253
return NULL;
259254
}

0 commit comments

Comments
 (0)