src/timer/psp/SDL_systimer.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 29 Oct 2014 20:20:47 +0100
changeset 9201 21d9f9babb30
parent 8268 3f8410f20405
child 9328 b21d3417260a
permissions -rw-r--r--
Fixed bug 2647 - Memory leak in SDL_AddHintCallback function - SDL_hints.c

Nitz

Variable entry going out of scope leaks the storage it points to, at:

/* Need to add a hint entry for this watcher */
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
if (!hint) {
return;
}

Patch is attached.
kimonline@7009
     1
/*
kimonline@7009
     2
  Simple DirectMedia Layer
slouken@8149
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
kimonline@7009
     4
kimonline@7009
     5
  This software is provided 'as-is', without any express or implied
kimonline@7009
     6
  warranty.  In no event will the authors be held liable for any damages
kimonline@7009
     7
  arising from the use of this software.
kimonline@7009
     8
kimonline@7009
     9
  Permission is granted to anyone to use this software for any purpose,
kimonline@7009
    10
  including commercial applications, and to alter it and redistribute it
kimonline@7009
    11
  freely, subject to the following restrictions:
kimonline@7009
    12
kimonline@7009
    13
  1. The origin of this software must not be misrepresented; you must not
kimonline@7009
    14
     claim that you wrote the original software. If you use this software
kimonline@7009
    15
     in a product, an acknowledgment in the product documentation would be
kimonline@7009
    16
     appreciated but is not required.
kimonline@7009
    17
  2. Altered source versions must be plainly marked as such, and must not be
kimonline@7009
    18
     misrepresented as being the original software.
kimonline@7009
    19
  3. This notice may not be removed or altered from any source distribution.
kimonline@7009
    20
*/
kimonline@7009
    21
kimonline@7009
    22
#include "SDL_thread.h"
kimonline@7009
    23
#include "SDL_timer.h"
kimonline@7009
    24
#include "SDL_error.h"
kimonline@7009
    25
#include "../SDL_timer_c.h"
kimonline@7009
    26
#include <stdlib.h>
kimonline@7009
    27
#include <time.h>
kimonline@7009
    28
#include <sys/time.h>
kimonline@7009
    29
#include <pspthreadman.h>
kimonline@7009
    30
kimonline@7009
    31
static struct timeval start;
urkle@7649
    32
static SDL_bool ticks_started = SDL_FALSE;
kimonline@7009
    33
slouken@8268
    34
void
slouken@8268
    35
SDL_TicksInit(void)
kimonline@7009
    36
{
urkle@7649
    37
    if (ticks_started) {
urkle@7649
    38
        return;
urkle@7649
    39
    }
urkle@7649
    40
    ticks_started = SDL_TRUE;
urkle@7649
    41
slouken@7191
    42
    gettimeofday(&start, NULL);
kimonline@7009
    43
}
kimonline@7009
    44
slouken@8268
    45
void
slouken@8268
    46
SDL_TicksQuit(void)
slouken@8268
    47
{
slouken@8268
    48
    ticks_started = SDL_FALSE;
slouken@8268
    49
}
slouken@8268
    50
kimonline@7009
    51
Uint32 SDL_GetTicks(void)
kimonline@7009
    52
{
urkle@7649
    53
    if (!ticks_started) {
slouken@8268
    54
        SDL_TicksInit();
urkle@7649
    55
    }
urkle@7649
    56
slouken@7191
    57
    struct timeval now;
slouken@7191
    58
    Uint32 ticks;
kimonline@7009
    59
slouken@7191
    60
    gettimeofday(&now, NULL);
slouken@7191
    61
    ticks=(now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000;
slouken@7191
    62
    return(ticks);
kimonline@7009
    63
}
kimonline@7009
    64
kimonline@7009
    65
Uint64
kimonline@7009
    66
SDL_GetPerformanceCounter(void)
kimonline@7009
    67
{
kimonline@7009
    68
    return SDL_GetTicks();
kimonline@7009
    69
}
kimonline@7009
    70
kimonline@7009
    71
Uint64
kimonline@7009
    72
SDL_GetPerformanceFrequency(void)
kimonline@7009
    73
{
kimonline@7009
    74
    return 1000;
kimonline@7009
    75
}
kimonline@7009
    76
kimonline@7009
    77
void SDL_Delay(Uint32 ms)
kimonline@7009
    78
{
slouken@7191
    79
    const Uint32 max_delay = 0xffffffffUL / 1000;
slouken@7191
    80
    if(ms > max_delay)
slouken@7191
    81
        ms = max_delay;
slouken@7191
    82
    sceKernelDelayThreadCB(ms * 1000);
kimonline@7009
    83
}
kimonline@7009
    84
kimonline@7009
    85
/* vim: ts=4 sw=4
kimonline@7009
    86
 */