Skip to content

Commit fbf56c2

Browse files
authored
Merge pull request #72 from bfansports/feature/memory-leak-fixes
Fix memory leaks
2 parents 5ba6d3c + 86c98a0 commit fbf56c2

3 files changed

Lines changed: 45 additions & 38 deletions

File tree

src/activities/TranscodeAssetActivity.php

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,32 +181,36 @@ private function uploadResultFiles($task, $output)
181181
self::TMP_PATH_OPEN_FAIL);
182182
}
183183

184-
// Upload all resulting files sitting in $outputFilesPath to S3
185-
while ($entry = readdir($handle)) {
186-
if ($entry == "." || $entry == "..") {
187-
continue;
188-
}
184+
try {
185+
// Upload all resulting files sitting in $outputFilesPath to S3
186+
while ($entry = readdir($handle)) {
187+
if ($entry == "." || $entry == "..") {
188+
continue;
189+
}
190+
191+
// Destination path on S3. Sanitizing
192+
$s3Location = $output->{'output_file_info'}['dirname']."/$entry";
193+
$s3Location = str_replace("//", "/", $s3Location);
194+
195+
// Send to S3. We reference the callback s3_put_processing_callback
196+
// The callback ping back SWF so we stay alive
197+
$s3Output = $this->s3Utils->put_file_into_s3(
198+
$s3Bucket,
199+
$s3Location,
200+
"$this->outputFilesPath/$entry",
201+
$options,
202+
array($this, "activityHeartbeat"),
203+
null
204+
);
205+
// We delete the TMP file once uploaded
206+
unlink("$this->outputFilesPath/$entry");
189207

190-
// Destination path on S3. Sanitizing
191-
$s3Location = $output->{'output_file_info'}['dirname']."/$entry";
192-
$s3Location = str_replace("//", "/", $s3Location);
193-
194-
// Send to S3. We reference the callback s3_put_processing_callback
195-
// The callback ping back SWF so we stay alive
196-
$s3Output = $this->s3Utils->put_file_into_s3(
197-
$s3Bucket,
198-
$s3Location,
199-
"$this->outputFilesPath/$entry",
200-
$options,
201-
array($this, "activityHeartbeat"),
202-
null
203-
);
204-
// We delete the TMP file once uploaded
205-
unlink("$this->outputFilesPath/$entry");
206-
207-
$this->cpeLogger->logOut("INFO", basename(__FILE__),
208-
$s3Output['msg'],
209-
$this->logKey);
208+
$this->cpeLogger->logOut("INFO", basename(__FILE__),
209+
$s3Output['msg'],
210+
$this->logKey);
211+
}
212+
} finally {
213+
closedir($handle);
210214
}
211215
}
212216

src/activities/ValidateAssetActivity.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,23 @@ public function process($task)
9191
$this->curl_data = '';
9292

9393
$ch = curl_init();
94-
curl_setopt($ch, CURLOPT_URL, $this->input->{'input_asset'}->{'http'});
95-
curl_setopt($ch, CURLOPT_RANGE, '0-1024');
96-
curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'writefn'));
97-
curl_exec($ch);
98-
if ($errno = curl_errno($ch)) {
99-
if ($errno != CURLE_WRITE_ERROR) {
100-
$error_message = curl_strerror($errno);
101-
throw new CpeSdk\CpeException(
102-
$error_message,
103-
self::VALIDATE_ASSET_FAILED
104-
);
94+
try {
95+
curl_setopt($ch, CURLOPT_URL, $this->input->{'input_asset'}->{'http'});
96+
curl_setopt($ch, CURLOPT_RANGE, '0-1024');
97+
curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'writefn'));
98+
curl_exec($ch);
99+
if ($errno = curl_errno($ch)) {
100+
if ($errno != CURLE_WRITE_ERROR) {
101+
$error_message = curl_strerror($errno);
102+
throw new CpeSdk\CpeException(
103+
$error_message,
104+
self::VALIDATE_ASSET_FAILED
105+
);
106+
}
105107
}
108+
} finally {
109+
curl_close($ch);
106110
}
107-
curl_close($ch);
108111

109112
$chunk = $this->curl_data;
110113
}

src/scripts/putInS3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function check_input_parameters(&$options)
4747
try {
4848
# Check if preper env vars are setup
4949
if (!($region = getenv("AWS_DEFAULT_REGION")))
50-
throw new CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!");
50+
throw new \SA\CpeSdk\CpeException("Set 'AWS_DEFAULT_REGION' environment variable!");
5151

5252
// Get S3 client
5353
$s3 = new \Aws\S3\S3Client([

0 commit comments

Comments
 (0)