- av_strlcpy(sub_path, dirname, sub_path_size);
- av_strlcat(sub_path, segment->sub_filename, sub_path_size);
- if (unlink(sub_path) < 0) {
- av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
- sub_path, strerror(errno));
+ if (segment->sub_filename[0] != '\0') {
+ sub_path_size = strlen(dirname) + strlen(segment->sub_filename) + 1;
+ sub_path = av_malloc(sub_path_size);
+ if (!sub_path) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ av_strlcpy(sub_path, dirname, sub_path_size);
+ av_strlcat(sub_path, segment->sub_filename, sub_path_size);
+ if (unlink(sub_path) < 0) {
+ av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
+ sub_path, strerror(errno));
+ }
+ av_free(sub_path);